In the project, you need to merge multiple EXCEL reports and use multiple sheets in one Excel file. The code for the consolidated report is as follows:
Private void btnexport_click (Object sender, eventargs E)
{String filename = ""; system. windows. forms. filedialog DLG = NULL; DLG = new savefiledialog (); // set the file string DLG according to the format. filter = This. getfilefilterstring (); // open the file if (DLG. showdialog () = dialogresult. OK) {filename = DLG. filename;} If (DLG. filename. equals ("") {return;} // generate the report this. export (filename); string dir = filename. substring (0, filename. lastindexof ("//"); // The report is merged into Microsoft. office. interOP. excel. application Excel = new Microsoft. office. interOP. excel. applicationclass (); Microsoft. office. interOP. excel. workbook workbook1 = excel. workbooks. open (DIR + "// file0.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. workbook workbook2 = excel. workbooks. open (DIR + "// file1.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. workbook workbook3 = excel. workbooks. open (DIR + "// file2.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. workbook workbook4 = excel. workbooks. open (DIR + "// file3.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. workbook workbook5 = excel. workbooks. open (DIR + "// file4.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. workbook workbook6 = excel. workbooks. open (DIR + "// file5.xls", type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing, type. missing); Microsoft. office. interOP. excel. worksheet worksheet1 = (Microsoft. office. interOP. excel. worksheet) workbook1.sheets ["sheet1"]; Microsoft. office. interOP. excel. worksheet worksheet2 = (Microsoft. office. interOP. excel. worksheet) workbook2.sheets ["sheet1"]; Microsoft. office. interOP. excel. worksheet worksheet3 = (Microsoft. office. interOP. excel. worksheet) workbook3.sheets ["sheet1"]; Microsoft. office. interOP. excel. worksheet worksheet4 = (Microsoft. office. interOP. excel. worksheet) workbook4.sheets ["sheet1"]; Microsoft. office. interOP. excel. worksheet worksheet5 = (Microsoft. office. interOP. excel. worksheet) workbook5.sheets ["sheet1"]; Microsoft. office. interOP. excel. worksheet worksheet6 = (Microsoft. office. interOP. excel. worksheet) workbook6.sheets ["sheet1"]; // sets the Report Sheet Name worksheet1.name = "real-time asset information"; worksheet2.name = "real-time position list"; worksheet3.name = "asset information "; worksheet4.name = "securities balance"; worksheet5.name = "capital flow summary"; worksheet6.name = "Capital Flow Summary 1"; // consolidated report worksheet6.copy (missing. value, worksheet1); worksheet5.copy (missing. value, worksheet1); worksheet4.copy (missing. value, worksheet1); worksheet3.copy (missing. value, worksheet1); worksheet2.copy (missing. value, worksheet1); workbook1.save (); workbook1.close (false, type. missing, type. missing); workbook2.close (false, type. missing, type. missing); workbook3.close (false, type. missing, type. missing); workbook4.close (false, type. missing, type. missing); workbook5.close (false, type. missing, type. missing); workbook6.close (false, type. missing, type. missing); // if the report file exists, delete if (file. exists (filename) {file. delete (filename);} file. copy (DIR + "// file0.xls", filename); // Delete the temporary file for (INT I = 0; I <6; I ++) {file. delete (DIR + "// file" + I + ". xls ");}}