导出到多张纸 [英] Export to multiple sheet
本文介绍了导出到多张纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能告诉我如何将数据从数据集中的excel文件中保存为3张,如果数据集中的行数为65536 * 3.我不想定义3张的事情,如果保存了1张由65536行组成,然后下一个65536行应保存在第二张表中,依此类推,保存在相同的excel文件中.plz帮助bcoz自4天以来尝试制作一个程序,通过该程序我可以将数据集从数据集动态保存到多张表中的excel. div class ="h2_lin">解决方案
for ( int i = 1 ; i < = ViewData.Rows.Count/ 65536 + 1 ; i ++) { xlworkSheet =(Excel.Worksheet)xlworkBook.Worksheets.get_Item(i); range = 空; range = xlworkSheet.get_Range(" ,misValue); range = range.get_Resize(DS.Tables [ 0 ].Rows.Count,DS.Tables [ 0 ] .Columns.Count); 如果( 65536 * i >< DS .Tables [ 0 ].Rows.Count) { 如果(i < = 1 ) { for (RRow = RRow; RRow < = 65536 * i- 1 ; ++ Row) { for ( int RColm = 0 ; RColm < ViewData.Cols.Count-1; RColm ++) { tempArray [RRow,RColm] = DS.Tables [ 0 ].Rows [RRow] .ItemArray [RColm] .ToString(); } } range.set_Value(System.Reflection.Missing.Value,tempArray); Array.Clear(tempArray, 0 ,tempArray.Length); tempArray = 新 字符串 [ViewData.Rows.Count,ViewData.Cols.Count]; } 其他 { int tempRow = 0 ; for (RRow = RRow; RRow < ViewData.Rows.Count- for ( int RColm = 0 ; RColm < ViewData.Cols.Count- 1 ; RColm ++) { tempArray [tempRow,RColm] = DS.Tables [ 0 ].Rows [RRow] .ItemArray [RColm] .ToString(); } tempRow ++; } range.set_Value(System.Reflection.Missing.Value,tempArray); } } 其他 { int tempRow = 0 ; for (RRow = RRow; RRow < ViewData.Rows.Count- for ( int RColm = 0 ; RColm < ViewData.Cols.Count- 1 ; RColm ++) { tempArray [tempRow,RColm] = DS.Tables [ 0 ].Rows [RRow] .ItemArray [RColm] .ToString(); } tempRow ++; } range.set_Value(System.Reflection.Missing.Value,tempArray); xlworkBook.SaveAs(" ,Excel.XlFileFormat.xlWorkbookNormal,misValue,misValue,misValue, misValue,Excel.XlSaveAsAccessMode.xlExclusive,misValue,misValue,misValue,misValue,misValue); } } xlApp.UserControl = true ; Process pro = Process.Start(" );
//这是我创造并成功实现的逻辑.我们可以从用户的角度做一些更好的事情
使用XLSX
文件格式,该格式最多可以达到一百万行.
尝试以下组件: http://epplus.codeplex.com/ [ 解决方案
for (int i = 1; i <= ViewData.Rows.Count / 65536 + 1; i++) { xlworkSheet = (Excel.Worksheet)xlworkBook.Worksheets.get_Item(i); range = null; range = xlworkSheet.get_Range("A1", misValue); range = range.get_Resize(DS.Tables[0].Rows.Count,DS.Tables[0].Columns.Count); if (65536 * i < DS.Tables[0].Rows.Count) { if (i <= 1) { for (RRow = RRow; RRow <= 65536 * i - 1; ++RRow) { for (int RColm = 0; RColm < ViewData.Cols.Count-1; RColm++) { tempArray[RRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString(); } } range.set_Value(System.Reflection.Missing.Value, tempArray); Array.Clear(tempArray, 0, tempArray.Length); tempArray = new string[ViewData.Rows.Count, ViewData.Cols.Count]; } else { int tempRow = 0; for (RRow = RRow; RRow < ViewData.Rows.Count - 1; ++RRow) { for (int RColm = 0; RColm < ViewData.Cols.Count - 1; RColm++) { tempArray[tempRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString(); } tempRow++; } range.set_Value(System.Reflection.Missing.Value, tempArray); } } else { int tempRow = 0; for (RRow = RRow; RRow < ViewData.Rows.Count - 1; ++RRow) { for (int RColm = 0; RColm < ViewData.Cols.Count - 1; RColm++) { tempArray[tempRow, RColm] = DS.Tables[0].Rows[RRow].ItemArray[RColm].ToString(); } tempRow++; } range.set_Value(System.Reflection.Missing.Value, tempArray); xlworkBook.SaveAs("Myfile.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); } } xlApp.UserControl = true; Process pro = Process.Start("myfilepath");
//this is the logic,I have created and success to make.We can do some better from user point of view
Use theXLSX
file format which can go up to 1 million rows.
Try this component : http://epplus.codeplex.com/[^]
这篇关于导出到多张纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文