PC Review


Reply
Thread Tools Rate Thread

How to create a new worksheet from a template?

 
 
fenguo
Guest
Posts: n/a
 
      22nd Jul 2007
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.


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      22nd Jul 2007
Workbooks.Add _
(Template:="C:\Documents and _
Settings\new\Application\Data\Microsoft\Templates\aaa.xlt")

"fenguo" wrote:

> 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.
>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      22nd Jul 2007
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.

fenguo wrote:
>
> 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.


--

Dave Peterson
 
Reply With Quote
 
fenguo
Guest
Posts: n/a
 
      22nd Jul 2007
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" <(E-Mail Removed)> 写入消息新闻:B41F82F3-D190-4A4C-98D2-(E-Mail Removed)...
> Workbooks.Add _
> (Template:="C:\Documents and _
> Settings\new\Application\Data\Microsoft\Templates\aaa.xlt")
>
> "fenguo" wrote:
>
>> 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.
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create new worksheet from template for each value in range CJ Microsoft Excel Worksheet Functions 6 15th Nov 2007 06:19 AM
How do I create a new worksheet using a template or xls file John Microsoft Excel Programming 0 25th Mar 2006 06:15 PM
create a master worksheet template =?Utf-8?B?RGVyZWs=?= Microsoft Excel Misc 0 10th Jan 2006 03:38 PM
Create a template for every worksheet =?Utf-8?B?QWxhbmE=?= Microsoft Excel Misc 0 8th Mar 2005 09:49 PM
Create a single worksheet from a template Shaz Microsoft Excel Discussion 2 2nd May 2004 09:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:12 AM.