473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 19 '05 #1
2 1423
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 19 '05 #2
thank you
but for using the system clipboard in asp.net need which permissions?

i have config Microsoft Excel Application in dcomcnfg.exe and asp.net/iis
users is in administrator group.

and
ExcelMainFileWorksheet.Copy(ExcelSubFileWorkbook.S heets[ExcelSubFileWorkbook
..Sheets.Count-1],Type.Missing); failed in winform now.
it seems copy function just can be used in one excel app with different
workbooks or one workbook.

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TC | last post by:
Hello, Here is what I'm trying to do: -- Make sure both MS Excel and MS Word are running -- Create an Excel chart -- Save the Excel file -- Copy the Excel chart onto the clipboard using Ctrl...
3
by: Otie | last post by:
I am trying to copy the cell contents in an MSFLXGRD control (using VB5) into Excel, retaining the foreground colors of the text and numbers. I have tried using the Clipboard.SetText...
2
by: TC | last post by:
Hello, Here is what I'm trying to do: -- Make sure both MS Excel and MS Word are running -- Create an Excel chart -- Save the Excel file -- Copy the Excel chart onto the clipboard using Ctrl...
2
by: TC | last post by:
Hello, Here is what I'm trying to do: -- Make sure both MS Excel and MS Word are running -- Create an Excel chart -- Save the Excel file -- Copy the Excel chart onto the clipboard using Ctrl...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.