Excel工作表的开放一次,在其上写迭代 [英] Opening of Excel sheet once and writing on it iteratively
本文介绍了Excel工作表的开放一次,在其上写迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#应用程序已以书面形式向Excel工作表一个概率。
我的应用程序为它的目的创建的Excel工作表,并在它不写。
下面code仅供参考。
my app in c# has a prob in writing to excel sheet. My app create excel sheet for its purpose and does not write in it. the below code is for reference only..
class a
{
void m()
{
b bee=new b();
Excel.Application oXL;
Excel._Workbook oWB;
b.write(oXL,oWB); //will be called multiple times
}
}
class b
{
static b() //declared static so that only once excel workbook with sheets will be created
{
Excel._Application oXL = new Excel.Application();
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Type.Missing));
}
write( Excel.Application oXL, Excel._Workbook oWB)
{
oXL.Visible = true; //Here its throwing, Object reference not set to an instance of an
//Object
}
}
帮助将AP preciated,先谢谢了!
Help will be appreciated, thanks in advance!
推荐答案
我想你想有大致如下的行code:
I think you want to have code along the lines of the following:
class a
{
b bee;
public a()
{
bee = new b();
}
void m()
{
b.write(oXL,oWB); //will be called multiple times
}
}
class b
{
public b()
{
Excel._Application oXL = new Excel.Application();
Excel._Workbook oWB = (Excel._Workbook)(oXL.Workbooks.Add(Type.Missing));
}
write()
{
oXL.Visible = true;
}
}
您则需要确保,您所创建的只是尽可能多的情况下, A
你想要的Excel工作表。
You then need to make sure, that you create only as many instances of a
as you want Excel sheets.
您可以使用它是这样的:
You can use it like this:
a aa = new a();
for(...)
aa.m();
这篇关于Excel工作表的开放一次,在其上写迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文