469,927 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

about asp.net excel and clipboard

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.O pen(MainFile,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missin g,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing,Type.Miss ing,Type.Missing,Type.Miss
ing,Type.Missing);
ExcelMainFileWorksheet=(Excel._Worksheet)ExcelMain FileWorkbook.ActiveSheet;
string name=ExcelMainFileWorksheet.Name;
ExcelMainFileWorksheet.Cells.Copy(Type.Missing);

ExcelSubFileApp = new Excel.Application();
//destination
ExcelSubFileWorkbook=ExcelSubFileApp.Workbooks.Ope n(SubFile,Type.Missing,Typ
e.Missing,Type.Missing,Type.Missing,Type.Missing,T ype.Missing,Type.Missing,T
ype.Missing,Type.Missing,Type.Missing,Type.Missing ,Type.Missing,Type.Missing
,Type.Missing);
ExcelSubFileWorksheet=(Excel._Worksheet)ExcelSubFi leWorkbook.Sheets.Add(Exce
lSubFileWorkbook.Sheets[ExcelSubFileWorkbook.Sheets.Count],Type.Missing,Type
..Missing,Type.Missing);
ExcelSubFileWorksheet.Paste(Type.Missing,Type.Miss ing);//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.Miss ing); "

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?
Nov 17 '05 #1
1 3202
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
--------------------------------------------------
"使名扬" <to*************@hotmail.com> wrote in message
news:OO*************@TK2MSFTNGP12.phx.gbl...
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.O pen(MainFile,Type.Missing,
Type.Missing,Type.Missing,Type.Missing,Type.Missin g,Type.Missing,Type.Missin
g,Type.Missing,Type.Missing,Type.Missing,Type.Miss ing,Type.Missing,Type.Miss
ing,Type.Missing);
ExcelMainFileWorksheet=(Excel._Worksheet)ExcelMain FileWorkbook.ActiveSheet;
string name=ExcelMainFileWorksheet.Name;
ExcelMainFileWorksheet.Cells.Copy(Type.Missing);

ExcelSubFileApp = new Excel.Application();
//destination
ExcelSubFileWorkbook=ExcelSubFileApp.Workbooks.Ope n(SubFile,Type.Missing,Typ
e.Missing,Type.Missing,Type.Missing,Type.Missing,T ype.Missing,Type.Missing,T
ype.Missing,Type.Missing,Type.Missing,Type.Missing ,Type.Missing,Type.Missing
,Type.Missing);
ExcelSubFileWorksheet=(Excel._Worksheet)ExcelSubFi leWorkbook.Sheets.Add(Exce
lSubFileWorkbook.Sheets[ExcelSubFileWorkbook.Sheets.Count],Type.Missing,Type
.Missing,Type.Missing);
ExcelSubFileWorksheet.Paste(Type.Missing,Type.Miss ing);//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.Miss ing); "

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?

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Otie | last post: by
2 posts views Thread by 使名扬 | last post: by
reply views Thread by Pieter | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.