PC Review


Reply
Thread Tools Rate Thread

about asp.net excel and clipboard

 
 
ʹÃûÑï
Guest
Posts: n/a
 
      24th Apr 2005
hi:

purpose: clone the firest sheet in Excel.xls into excel2.xls

here is my code
it well done in winform£º
-------------------------------
string SubFile=@"D:\Excel2.xls";
string MainFile=@"D:\Excel.xls";
Excel.Application ExcelMainFileApp,ExcelSubFileApp;
Excel._Workbook ExcelMainFileWorkbook,ExcelSubFileWorkbook;
Excel._Worksheet ExcelMainFileWorksheet,ExcelSubFileWorksheet;
try
{
ExcelMainFileApp = new Excel.Application();

//open source
ExcelMainFileWorkbook=ExcelMainFileApp.Workbooks.Open(MainFile,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Miss
ing,Type.Missing);


ExcelMainFileWorksheet=(Excel._Worksheet)ExcelMainFileWorkbook.ActiveSheet;
string name=ExcelMainFileWorksheet.Name;
ExcelMainFileWorksheet.Cells.Copy(Type.Missing);

ExcelSubFileApp = new Excel.Application();


//destination
ExcelSubFileWorkbook=ExcelSubFileApp.Workbooks.Open(SubFile,Type.Missing,Typ
e.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,T
ype.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing
,Type.Missing);
ExcelSubFileWorksheet=(Excel._Worksheet)ExcelSubFileWorkbook.Sheets.Add(Exce
lSubFileWorkbook.Sheets[ExcelSubFileWorkbook.Sheets.Count],Type.Missing,Type
..Missing,Type.Missing);
ExcelSubFileWorksheet.Paste(Type.Missing,Type.Missing);//failed in webform
,when in winform it's ok
foreach (Excel.Workbook book in ExcelSubFileApp.Workbooks)
{
book.Save();
}
ExcelMainFileApp.Workbooks.Close();
ExcelSubFileApp.Workbooks.Close();
ExcelMainFileApp.Quit();
ExcelSubFileApp.Quit();
}
catch( Exception theException )
{
}
finally
{

}
-------------------------------
but when in webform ,it's failed in "
ExcelSubFileWorksheet.Paste(Type.Missing,Type.Missing); "

i have configed the DCOM right about excel .
(run dcomcnfg.exe and config Microsoft Excel Application.)
but it's still fail (without config it failed in "ExcelMainFileApp =
new Excel.Application();")

anybody knows why?


 
Reply With Quote
 
 
 
 
Alvin Bruney [Microsoft MVP]
Guest
Posts: n/a
 
      24th Apr 2005
for staters you didn't say what was wrong. secondly, you don't need to
multi-post - this problem has nothing to do with dotnet.framework for
example. there is also a worksheet copy function that you can use to copy
but it uses the system clipboard and you need appropriate permissions

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc
--------------------------------------------------


"ʹÃûÑï" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> hi:
>
> purpose: clone the firest sheet in Excel.xls into excel2.xls
>
> here is my code
> it well done in winform£º
> -------------------------------
> string SubFile=@"D:\Excel2.xls";
> string MainFile=@"D:\Excel.xls";
> Excel.Application ExcelMainFileApp,ExcelSubFileApp;
> Excel._Workbook ExcelMainFileWorkbook,ExcelSubFileWorkbook;
> Excel._Worksheet ExcelMainFileWorksheet,ExcelSubFileWorksheet;
> try
> {
> ExcelMainFileApp = new Excel.Application();
>
> //open source
> ExcelMainFileWorkbook=ExcelMainFileApp.Workbooks.Open(MainFile,Type.Missing,
> Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missin
> g,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Miss
> ing,Type.Missing);
>
>
> ExcelMainFileWorksheet=(Excel._Worksheet)ExcelMainFileWorkbook.ActiveSheet;
> string name=ExcelMainFileWorksheet.Name;
> ExcelMainFileWorksheet.Cells.Copy(Type.Missing);
>
> ExcelSubFileApp = new Excel.Application();
>
>
> //destination
> ExcelSubFileWorkbook=ExcelSubFileApp.Workbooks.Open(SubFile,Type.Missing,Typ
> e.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,T
> ype.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing
> ,Type.Missing);
> ExcelSubFileWorksheet=(Excel._Worksheet)ExcelSubFileWorkbook.Sheets.Add(Exce
> lSubFileWorkbook.Sheets[ExcelSubFileWorkbook.Sheets.Count],Type.Missing,Type
> .Missing,Type.Missing);
> ExcelSubFileWorksheet.Paste(Type.Missing,Type.Missing);//failed in webform
> ,when in winform it's ok
> foreach (Excel.Workbook book in ExcelSubFileApp.Workbooks)
> {
> book.Save();
> }
> ExcelMainFileApp.Workbooks.Close();
> ExcelSubFileApp.Workbooks.Close();
> ExcelMainFileApp.Quit();
> ExcelSubFileApp.Quit();
> }
> catch( Exception theException )
> {
> }
> finally
> {
>
> }
> -------------------------------
> but when in webform ,it's failed in "
> ExcelSubFileWorksheet.Paste(Type.Missing,Type.Missing); "
>
> i have configed the DCOM right about excel .
> (run dcomcnfg.exe and config Microsoft Excel Application.)
> but it's still fail (without config it failed in "ExcelMainFileApp
> =
> new Excel.Application();")
>
> anybody knows why?
>
>



 
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
Transfer clipboard from Task pane clipboard(office?) content to Excel (windows?) clipboard? tskogstrom Microsoft Excel Programming 2 6th Mar 2007 12:50 PM
Clipboard gets empty by itself, cleared clipboard, copy paste doesn't work, outlook clears clipboard, problems with clipboard - possible solution Jens Hoerburger Microsoft Outlook 0 24th Aug 2006 02:44 PM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC Microsoft Dot NET 5 1st Sep 2004 05:49 AM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC Microsoft Dot NET Framework 5 1st Sep 2004 05:49 AM
Using VB.Net or C#, utilizing the clipboard object, how to copy an MS Excel graphic from the clipboard to an image control and obtain its source reference TC Microsoft VB .NET 2 27th Jul 2004 06:07 PM


Features
 

Advertising
 

Newsgroups
 


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