Merge two SLDocuments to one SLDocument

1.2k Views Asked by At

I'm using SpreadsheetLight to create 2 seperate spreadsheets. One of them is with a chart but both are having only one worksheet.

I'm trying to merge these two sheets into one spreadsheet with two worksheets. Each of the seperate sheets should be copied to one worksheet of the final file.

I've found only methods for copieing cells but not for an entire document. But this way is not an option because i also need the chart.

Thanks in Advance

1

There are 1 best solutions below

0
On BEST ANSWER

It seems you cant copy the chart, so... keep the chart, copy the other sheet and rename the resulting file:

SLDocument sheetDoc = new SLDocument("ChartSheet.xlsx"); //existing
SLDocument origDoc = new SLDocument("DataSheet.xlsx") //existing
sheetDoc.AddWorksheet("SecondSheet");
//loop to copy the needed information (whole sheet in this case):
    sheetDoc.SetCellValue("A1", origDoc.GetCellValueAsString("A1"));
    sheetDoc.SetCellValue("A2", origDoc.GetCellValueAsString("A2"));
    ...
//end loop
sheetDoc.SaveAs("FinalSheet.xlsx");

Hope this gets you on track