C# Winform里面输出数据到Excel的问题
2007-07-11 15:37
519 查看
using System;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
public class CreateExcelWorksheet
{
static void Main()
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
return;
}
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = (Worksheet)wb.Worksheets[1];
if (ws == null)
{
Console.WriteLine("Worksheet could not be created. Check that your office installation and project references are correct.");
}
// Select the Excel cells, in the range c1 to c7 in the worksheet.
Range aRange = ws.get_Range("C1", "C7");
if (aRange == null)
{
Console.WriteLine("Could not get a range. Check to be sure you have the correct versions of the office DLLs.");
}
// Fill the cells in the C1 to C7 range of the worksheet with the number 6.
Object[] args = new Object[1];
args[0] = 6;
aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, args);
// Change the cells in the C1 to C7 range of the worksheet to the number 8.
aRange.Value2 = 8;
}
}
using System.Reflection;
using Microsoft.Office.Interop.Excel;
public class CreateExcelWorksheet
{
static void Main()
{
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
Console.WriteLine("EXCEL could not be started. Check that your office installation and project references are correct.");
return;
}
xlApp.Visible = true;
Workbook wb = xlApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Worksheet ws = (Worksheet)wb.Worksheets[1];
if (ws == null)
{
Console.WriteLine("Worksheet could not be created. Check that your office installation and project references are correct.");
}
// Select the Excel cells, in the range c1 to c7 in the worksheet.
Range aRange = ws.get_Range("C1", "C7");
if (aRange == null)
{
Console.WriteLine("Could not get a range. Check to be sure you have the correct versions of the office DLLs.");
}
// Fill the cells in the C1 to C7 range of the worksheet with the number 6.
Object[] args = new Object[1];
args[0] = 6;
aRange.GetType().InvokeMember("Value", BindingFlags.SetProperty, null, aRange, args);
// Change the cells in the C1 to C7 range of the worksheet to the number 8.
aRange.Value2 = 8;
}
}
相关文章推荐
- 在winform开发中如何把datagrid里面的数据导出成EXCEL文件
- C# WinForm 实现增删改查等功能(Access版) 系列之八-导出数据到Excel
- C#读取URL里面的XML数据问题
- C# 读取EXCEL文件出现数据丢失问题
- C# 将数据导出到Excel汇总Webform,Winform(转)
- C#.NET常见问题(FAQ)-如何使用DataGridView跟Excel数据交互
- C#读取excel文件数据丢失问题
- C# 操作数据导出到Excel遇到的一个小问题
- C#导入数据到Excel中遇到的问题,已解决
- C#Winformd读取excel文件数据转化为DataTable
- C# Winform实现数据的导出为txt或者CSV或者excel格式
- 用C#输出数据到excel的最简单的例子(By kiseigo)
- C# 导入excel数据,解决关闭excel后不能释放资源的问题
- C# 读取EXCEL文件出现数据丢失问题
- C# winform TabPage两个存在关联关系的窗体数据不刷新问题
- C# Winform Excel的导出,根据excel模板导出数据
- C# 读取EXCEL文件出现数据丢失问题,数据不完整
- C#如何从Excel里面导入数据
- C# 上传excel文档解析出里面数据
- C#导入excel数据表字符与数字同列出现的问题