C中数据导出到Excel表格(6)
发布时间:2021-06-07
发布时间:2021-06-07
DataGridView 数据导出到Excel
86. strLine = strLine + ds.Tables[0].Columns[i].ColumnName.ToString() + " " +
Convert.ToChar(9);
87. }
88. objStreamWriter.WriteLine(strLine);
89. strLine = "";
90.
91. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
92. {
93. strLine = strLine + (i + 1) + Convert.ToChar(9);
94. for (int j = 1; j < ds.Tables[0].Columns.Count; j++)
95. {
96. strLine = strLine + ds.Tables[0].Rows[i][j].ToString() + Convert.ToChar(9);
97. }
98. objStreamWriter.WriteLine(strLine);
99. strLine = "";
100. }
101. objStreamWriter.Close();
102. objFileStream.Close();
103.
104. //Microsoft.Office.Interop.Excel._Application xlapp = new ApplicationClass(); 105. //Workbook xlbook = xlapp.Workbooks.Add(true);
106. //Worksheet xlsheet = (Worksheet)xlbook.Worksheets[1];
107. //Range range = xlsheet.get_Range(xlapp.Cells[1, 1], xlapp.Cells[1,
ds.Tables[0].Columns.Count]);
108. //range.EntireColumn.AutoFit();
109. //xlapp.Quit();
110. return true;
111. }
112. }
三、生成XML然后转换成Excel方式
参考资源:
/office/Excel_Export.asp?df=100&forumid=329437&fr=51 (源程序)
优点:
上一篇:红楼梦人物描写风格浅析
下一篇:美国联邦制的发展。