哪位大神有C#WEB项目把数据导出Excel表格的代码在线等挺急的
1条回答 默认 最新
- VBORNOT 2017-11-15 08:44关注
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Xml;
using System.Net;
using System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using System.Drawing;
using System.Reflection;namespace Export
{
class Export
{
public bool ExportForAVGTR(System.Data.DataTable AVGTR,string name)
{
//建立Excel对象
Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
try
{
app.Visible = false;
Microsoft.Office.Interop.Excel.Workbook xlBook = app.Workbooks.Add(true);
Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlBook.Worksheets[1];
for (int i = 0; i < AVGTR.Columns.Count; i++)
xlSheet.Cells[1, i + 1] = AVGTR.Columns[i].ColumnName.ToString();
for (int i = 0; i < AVGTR.Rows.Count; i++)
{
for (int j = 0; j < AVGTR.Columns.Count; j++)
{
xlSheet.Cells[i + 2, j + 1] = AVGTR.Rows[i][j].ToString();
}
}
xlSheet.Name = name;
xlSheet.Cells.Font.Size = 11;
xlSheet.Cells.Font.FontStyle = FontStyle.Bold;
xlSheet.Cells.Font.Name = "微软雅黑";
xlSheet.Columns.AutoFit();
}
finally
{
app.Visible = true;
}
return true;
}}
}
解决 无用评论 打赏 举报
悬赏问题
- ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
- ¥15 matlab有关常微分方程的问题求解决
- ¥15 perl MISA分析p3_in脚本出错
- ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
- ¥15 ubuntu虚拟机打包apk错误
- ¥199 rust编程架构设计的方案 有偿
- ¥15 回答4f系统的像差计算
- ¥15 java如何提取出pdf里的文字?
- ¥100 求三轴之间相互配合画圆以及直线的算法
- ¥100 c语言,请帮蒟蒻写一个题的范例作参考