[C#] 纯文本查看 复制代码
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("省/市",typeof(string)),//如果这里有斜线就会报错,去掉就好了
new DataColumn("城市",typeof(string)),
new DataColumn("地区",typeof(string)),
new DataColumn("数量",typeof(string))
});
DataRow row1 = dt.NewRow();
row1[0] = "北京";
row1[1] = "海淀";
row1[2] = "海淀";
row1[3] = "100";
dt.Rows.Add(row1);
DataRow row2 = dt.NewRow();
row2[0] = "北京";
row2[1] = "朝阳";
row2[2] = "朝阳";
row2[3] = "150";
dt.Rows.Add(row2);
DataRow row3 = dt.NewRow();
row3[0] = "北京";
row3[1] = "丰台";
row3[2] = "丰台";
row3[3] = "100";
dt.Rows.Add(row3);
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "Template";
sfd.Filter = "Excel文件|*.xls";
if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
bool bl = ExcelHelper_S.OutputToExcel(dt, sfd.FileName);
if (bl)
{
MessageBox.Show("导出成功");
}
else
{
MessageBox.Show("导出失败");
}
} 和20楼一样的情况,困扰了我半天
|