C#中将数据导到excel中
来源:互联网 发布:模拟笛子发音软件 编辑:程序博客网 时间:2024/04/30 08:40
需引入microsoft.office.interop
privateMicrosoft.Office.Interop.Excel.Application myExcel = null;
private void ExprotExcel1()
{
List<Process> processes =GetExcelProcesses();
if (processes.Count > 0)
{
MessageBox.Show("请关闭其他的Excel程序,以便进行导出!");
return;
}
dsProducts.ProductsDataTableproductsTable = new dsProducts.ProductsDataTable();
productsTable.AcceptChanges();
this.Cursor = Cursors.WaitCursor;
//保存文化环境
System.Globalization.CultureInfoCurrentCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = newSystem.Globalization.CultureInfo("en-US");
//保存文化环境
myExcel.Application.Workbooks.Add(true);
myExcel.Visible = true;
myExcel.Cells[1, 1] ="Northwind数据库产品表";
//填充标题
for (int i = 0; i < productsTable.Columns.Count;i++)
{
myExcel.Cells[2, i + 1] =productsTable.Columns[i].Caption;
}
//填充标题
dsProductsTableAdapters.ProductsTableAdapter adtProducts = newWindowsApplication1.dsProductsTableAdapters.ProductsTableAdapter();
productsTable =adtProducts.GetProducts();
//填充数据
for (int i = 0; i <productsTable.Rows.Count; i++)
{
for (int j = 0; j <productsTable.Columns.Count; j++)
{
if(productsTable.Rows[i][j].GetType() == typeof(System.String))
{
//从第3行开始
myExcel.Cells[i + 3, j+ 1] = "'" + productsTable.Rows[i][j].ToString();
}
else
{
//从第3行开始
myExcel.Cells[i + 3, j+ 1] = productsTable.Rows[i][j].ToString();
}
}
}
//恢复文化环境
System.Threading.Thread.CurrentThread.CurrentCulture = CurrentCI;
this.Cursor = Cursors.Default;
MessageBox.Show("导出成功!", "恭喜",MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
- C#中将数据导到excel中
- c#中将数据库数据导出到EXCEL中
- C#中将ListView中数据导出到Excel代码
- C#中将dataGridView导到excel
- 如何提高C#中将数据导入到Excel的性能
- 如何将C#中将TextBox的数据以及从数据库中查询得到的数据导出到Excel中
- java中将数据和图片导出到Excel文件中
- java从数据库中将数据导入到excel中
- vb中将数据导出到excel表格中
- Java中将JTable中的数据导出到Excel中
- VC中将数据导出到Excel表格中
- netbeans中将表格中的数据写到Excel中
- C#中将DataGridView中数据导出至Excel
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- C#中将DataTable中数据导出到csv文件中
- GdPicture.NET使用教程:在PDF文件中添加水印
- Android布局属性详解
- GPRS封装数据报文怎样将数据传入数据库问题
- flash3D开发基础-------什么是AGAL(转)
- android 游戏开发之即时音效Demo
- C#中将数据导到excel中
- zoj1149-Dividing
- java中使用简单的filter
- 内存分配--频繁分配释放内存导致的性能问题的分析
- android,内存优化详解
- myeclipse10.0优化及SVN安装配置
- matlab样条工具箱的基本概念
- python调用Shell脚本:os.system(cmd)或os.popen(cmd)
- STB image library的使用