手机版

C中数据导出到Excel表格(5)

时间:2025-07-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. {

C中数据导出到Excel表格(5).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)