How to create a new worksheet from a template?

F

fenguo

Can someone tell me how to create a new worksheet from a template? I hope to
create a worksheet from a template. In VBA programe,we can use following
code:
Dim type1 As Variant
type1 = "C:\Documents and Settings\new\Application
Data\Microsoft\Templates\aaa.xlt"
Sheets.Add , Sheets("Sheet2"), 1, type1
But When i use following code in Visual C#:
string ws;
ws = "C:\\Documents and Settings\new\\Application
Data\\Microsoft\\Templates\\³É¼¨µ¥Ä£°å.xlt";
//eapp is a excel application object.
eapp.Worksheets.Add(Missing.Value,
eapp.Worksheets[1],Missing.Value ,ws );
I get a COMException that HRESULT:0x800A03EC.
Why? How can we create a new worksheet from a template by C#?
thank you.
 
M

Mike

Workbooks.Add _
(Template:="C:\Documents and _
Settings\new\Application\Data\Microsoft\Templates\aaa.xlt")
 
D

Dave Peterson

I don't speak visual C#, but why did you change from Sheets.add to
worksheets.add.

Sheets.add can accept a template parm. Worksheets.add won't do what you want.
Can someone tell me how to create a new worksheet from a template? I hope to
create a worksheet from a template. In VBA programe,we can use following
code:
Dim type1 As Variant
type1 = "C:\Documents and Settings\new\Application
Data\Microsoft\Templates\aaa.xlt"
Sheets.Add , Sheets("Sheet2"), 1, type1
But When i use following code in Visual C#:
string ws;
ws = "C:\\Documents and Settings\new\\Application
Data\\Microsoft\\Templates\\³É¼¨µ¥Ä£°å.xlt";
//eapp is a excel application object.
eapp.Worksheets.Add(Missing.Value,
eapp.Worksheets[1],Missing.Value ,ws );
I get a COMException that HRESULT:0x800A03EC.
Why? How can we create a new worksheet from a template by C#?
thank you.
 
F

fenguo

thank you.
I have solve the problem.
The problem is that i use wrong object. I should use sheets object instead
of worksheets object.
Mike said:
Workbooks.Add _
(Template:="C:\Documents and _
Settings\new\Application\Data\Microsoft\Templates\aaa.xlt")

fenguo said:
Can someone tell me how to create a new worksheet from a template? I hope
to
create a worksheet from a template. In VBA programe,we can use following
code:
Dim type1 As Variant
type1 = "C:\Documents and Settings\new\Application
Data\Microsoft\Templates\aaa.xlt"
Sheets.Add , Sheets("Sheet2"), 1, type1
But When i use following code in Visual C#:
string ws;
ws = "C:\\Documents and Settings\new\\Application
Data\\Microsoft\\Templates\\3¨¦?¡§¦Ì£¤?¡ê¡ã?.xlt";
//eapp is a excel application object.
eapp.Worksheets.Add(Missing.Value,
eapp.Worksheets[1],Missing.Value ,ws );
I get a COMException that HRESULT:0x800A03EC.
Why? How can we create a new worksheet from a template by C#?
thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top