Hi Haresh,
//Load source spreadsheet
var source = new Workbook(dir + “book2.xlsx”);
//Access Worksheet containing comments
var sourceSheet = source.Worksheets[0];
//Create another instance of Workbook to store the result
var destination = new Workbook();
//Access first Worksheet of the second Workbook
var destinationSheet = destination.Worksheets[0];
//Copy source Worksheet to new Workbook
destinationSheet.Copy(sourceSheet);
//Clear the contents of the copied Worksheet if you wish to copy only the comments
destinationSheet.Cells.ClearContents(0, 0, destinationSheet.Cells.MaxDataRow, destinationSheet.Cells.MaxDataColumn);
//Save Result
destination.Save(dir + “output.xlsx”);
I've tried your solution but it's work perfect with file which is not contain any other shape like textbox, picture, But if worksheet has picture or button or textbox it's also remain in new copied worksheet.
I only want to copy comment with formatting to another worksheet at same cell location which contain different data
Is there any other way to do so...?
Haresh
Hi,
//Load source spreadsheet
var source = new Workbook("e:\\test2\\book2_new1.xlsx");
//Access Worksheet containing comments
var sourceSheet = source.Worksheets[0];
//Create another instance of Workbook to store the result
var destination = new Workbook();
//Access first Worksheet of the second Workbook
var destinationSheet = destination.Worksheets[0];
//Copy source Worksheet to new Workbook
destinationSheet.Copy(sourceSheet);
//Clear the contents of the copied Worksheet if you wish to copy only the comments
destinationSheet.Cells.ClearContents(0, 0, destinationSheet.Cells.MaxDataRow, destinationSheet.Cells.MaxDataColumn);
**Aspose.Cells.Drawing.ShapeCollection shapes = destinationSheet.Shapes;**
**for (int i = shapes.Count -1; i >=0; i--)**
**{**
**if (!(shapes[i].GetType().ToString() == "Aspose.Cells.Drawing.CommentShape"))**
**{**
**shapes.RemoveAt(i);**
**}**
**}**
//Save Result
destination.Save("e:\\test2\\output1.xlsx");