I use the folowing code to copy a sheet from an existing Excel document to a new one:
Dim designer As New Aspose.Excel.ExcelDesigner designer.Open(TemplateString) Dim ResultExcelDoc As New Aspose.Excel.Excel Dim Sheet1 As Aspose.Excel.Worksheet = designer.Excel.Worksheets(0) ResultExcelDoc.Worksheets.Item(1).Copy(Sheet1)
The Source-Sheet however contains some layout-stuff like bordercolor, fontsettings and backgroundcolor, while teh copied sheet only contains teh cells and the text/values in it.
Is there a way to copy the full sheet to create a similar one?
@Bas,
Aspose.Cells has replaced Aspose.Excel which is no more under development now. This new product supports all the features of predecessor Aspose.Excel along with the support for different features in the latest versions of MS Excel. You can copy worksheet from one workbook to another with all the layout settings as shown in the following sample code:
// Create a new Workbook.
Workbook excelWorkbook0 = new Workbook();
// Get the first worksheet in the book.
Worksheet ws0 = excelWorkbook0.Worksheets[0];
// Put some data into header rows (A1:A4)
for (int i = 0; i < 5; i++)
{
ws0.Cells[i, 0].PutValue(string.Format("Header Row {0}", i));
}
// Put some detail data (A5:A999)
for (int i = 5; i < 1000; i++)
{
ws0.Cells[i, 0].PutValue(string.Format("Detail Row {0}", i));
}
// Define a pagesetup object based on the first worksheet.
PageSetup pagesetup = ws0.PageSetup;
pagesetup.PrintGridlines = true;
// The first five rows are repeated in each page...
// It can be seen in print preview.
pagesetup.PrintTitleRows = "$1:$5";
// Create another Workbook.
Workbook excelWorkbook1 = new Workbook();
// Get the first worksheet in the book.
Worksheet ws1 = excelWorkbook1.Worksheets[0];
// Name the worksheet.
ws1.Name = "MySheet";
// Copy data from the first worksheet of the first workbook into the
// first worksheet of the second workbook.
ws1.Copy(ws0);
// Save the excel file.
excelWorkbook1.Save("CopyWorksheetFromWorkbookToOther_out.xls");