简体   繁体   中英

Merge two SLDocuments to one SLDocument

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM