C中数据导出到Excel表格(5)
发布时间:2021-06-07
发布时间:2021-06-07
DataGridView 数据导出到Excel
54. xlsheet.Cells.ColumnWidth = ds.Tables[0].Rows[i][colIndex -
1].ToString().Length;
55. }
56. }
57.
58. xlbook.Saved = true;
59. xlbook.SaveCopyAs(filePath);
60. xlapp.Quit();
61. GC.Collect();
62. return true;
63. }
64.
65. public bool ExportToExcelOF(System.Data.DataSet ds, string ReportName)
66. {
67. if (ds.Tables[0].Rows.Count == 0)
68. {
69. MessageBox.Show("数据集为空");
70. }
71. string FileName = filePath;
72.
73. //System.Data.DataTable dt = new System.Data.DataTable();
74. FileStream objFileStream;
75. StreamWriter objStreamWriter;
76. string strLine = "";
77. objFileStream = new FileStream(FileName, FileMode.OpenOrCreate,
FileAccess.Write);
78. objStreamWriter = new StreamWriter(objFileStream,
System.Text.Encoding.Unicode);
79.
80. strLine = ReportName;
81. objStreamWriter.WriteLine(strLine);
82. strLine = "";
83.
84. for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
85. {
上一篇:红楼梦人物描写风格浅析
下一篇:美国联邦制的发展。