Hi all,
We have a Excel workbook with 2 worksheets (sheet1 and sheet2), each has page header and footer. We want to copy the whole content of sheet2 and put it after sheet 1's page footer. Please see the attached file for more information.
Does Infragistics.Excel support a capability to copy worksheet and it's content? If not, we would aprreciate if you could suggest a best way to achieve this. Thank you very much
Regards,
Kiet
Hello Kiet,
Maybe one possible approach to solve this task using Infragisitcs Excel engine, could be :
private void ultraButton2_Click(object sender, EventArgs e){ Infragistics.Documents.Excel.Workbook wb = new Infragistics.Documents.Excel.Workbook(); wb = Infragistics.Documents.Excel.Workbook.Load("..\\..\\Test.xlsx"); Infragistics.Documents.Excel.Worksheet worksheet = wb.Worksheets["Sheet1"]; Infragistics.Documents.Excel.Worksheet worksheet2 = wb.Worksheets["Sheet2"];
int ii = worksheet.Rows.Count(); foreach (WorksheetRow item in worksheet2.Rows) { ii++; foreach (WorksheetCell cell in item.Cells) { worksheet.Rows[ii].SetCellValue(cell.ColumnIndex, cell.Value); } }
wb.Save("..\\..\\Test.xlsx"); Process.Start("..\\..\\Test.xlsx");}
Another possible solution could be without using Infragistics Excel engine. If you choose this scenario, you should add Microsoft.Office.Interop.Excel library. In this case the sample code will be:
private void ultraButton2_Click(object sender, EventArgs e){ Excel.Application app = new Excel.Application(); app.Workbooks.Add("..\\..\\Test1.xlsx"); int worksheetCount = app.Workbooks[0].Worksheets.Count;
app.Workbooks[0].Activate(); for (int j = 1; j <= worksheetCount; j++) { Excel._Worksheet ws = (Excel._Worksheet)app.Workbooks[0].Worksheets[j]; ws.Select(Type.Missing); ws.Cells.Select();
Excel.Range sel = (Excel.Range)app.Selection; sel.Copy(Type.Missing);
Excel._Worksheet sheet = (Excel._Worksheet)app.Workbooks[1].Worksheets.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing); sheet.Paste(Type.Missing, Type.Missing); }}
Let me know if you have any further questions.
Regards
Have you been able to resolve your issue ? If you need any additional assistance don’t hesitate to ask.
Hi Georgi,
Thank you for your suggestion. I've found the solution by copying everything including cell values, merged regions, shapes, rows' height, and columns' width. It is not a perfect way to do it but it works for me.
Thanks for your response. If you hvae any questions, feel free to write us