在c#中能不能动态的生成一个excel文件,向里边添加数据?

yesman 2002-04-13 06:56:56
很急
...全文
83 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
dingsb 2002-04-13
  • 打赏
  • 举报
回复
using Excel;
class Excell
{ public static int Main()
{ Application exc = new Application();
Workbooks workbooks = exc.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet);
Sheets sheets = workbook.Worksheets;
_Worksheet worksheet = (_Worksheet) sheets.get_Item(1);
Range range1 = worksheet.get_Range("C1","C1");
exc.Visible=true;
const int nCells = 1;
Object[] args1 = new Object[1];
args1[0] = nCells;
range1.Value2=100;
}

www.online.com.cn里面有
wenzm 2002-04-13
  • 打赏
  • 举报
回复
可以吧,因为都是VBA编程啊
一下是一段C#中操作Word的代码,你看看有没有用
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
object fileName = openFileDialog1.FileName;
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;

// WordApp.Activate();
WordApp.Visible = true;

Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);

aDoc.Activate();

WordApp.Selection.TypeText("Copyright C# Corner");
WordApp.Selection.TypeParagraph();

}
saucer 2002-04-13
  • 打赏
  • 举报
回复
看看这篇文章

http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q302084

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧