Prizes & Awards
My Profile
Active Members
TodayLast 7 Days
more...
|
Forums » .NET » ASP.NET »
open an existing excel file in asp.net
Posted Date: 26 Dec 2008 Posted By: sindhu Member Level: Silver Points: 1
Responses:
5
|
I am trying to open existing excel file by the following
Excel.Application myExcelApp = new Excel.Application(); //myExcelApp.Workbooks.Open(filename, 0, true, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); string workbookPath = "f:/aspx/sindhu_scorpiochat/coastal.xls"; Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); foreach (Excel.Worksheet sheet in myExcelApp.Worksheets) { sheet.SaveAs(Path.Combine(Path.GetDirectoryName("coastal.xls"), sheet.Name) + "." + mode.ToLower(), Excel.XlFileFormat.xlCSV, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } myExcelApp.Workbooks.Close(); myExcelApp.Quit();
but it shows the error like "no overload for method open takes 15 arguments "
for this line of Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
how can i solve the problem pls tell me how to rectify it
thanks sindhu
|
Responses
|
| Author: Anand Babu S 26 Dec 2008 | Member Level: Gold | Rating:  Points: 3 | hi
actly parameter missmatching problem
just look at your code how many parameter do you really want.. check it out first and remove unwanted one.. then u ll get the answer...
Here someting u added more
Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
Thanks & Regards, Anand Babu S
| | Author: sindhu 26 Dec 2008 | Member Level: Silver | Rating:  Points: 2 | hi Anand, if i pass one argumement it shows the error like "no overload for method open takes 1 arguments "
so i can't identify the error pls tell me how to rectify it
| | Author: Anand Babu S 26 Dec 2008 | Member Level: Gold | Rating:  Points: 6 | Hi
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices; using System.IO;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
} protected void Button1_Click(object sender, EventArgs e) { //Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //Microsoft.Office.Interop.Excel.Workbook wb = null; //object missing = Type.Missing; //wb = excel.Workbooks.Open("c:\\test.xls", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); //excel.Visible = true;
string workbookPath = "c:\\test.xls"; Microsoft.Office.Interop.Excel.Application myExcelApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); foreach (Microsoft.Office.Interop.Excel.Worksheet sheet in myExcelApp.Worksheets) { sheet.SaveAs(Path.Combine(Path.GetDirectoryName("test.xls"), sheet.Name), Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } myExcelApp.Workbooks.Close(); myExcelApp.Quit();
} }
the above code working fine for me this ll crete the files in my machine well....
look at my sample ....
for more reference look at this ebook
http://books.google.co.in/books?id=iH-mkXUoeIQC&pg=PA50&lpg=PA50&dq=Excel.Application+myExcelApp&source=bl&ots=d_aGkatDr_&sig=IN02gnQpqEovimXPKdMRB-FuwU0&hl=en&sa=X&oi=book_result&resnum=1&ct=result#PPA58,M1
feel free to contact with this id nandhus1983@gmail.com
Thanks & Regards, Anand Babu S
WebSite3.rar | | Author: Arun Sahoo 12 Jan 2009 | Member Level: Bronze | Rating:  Points: 5 | Hi Friends, Please someone help me out.I am having following problem.
when I am trying to open existing excel file using following statement
Microsoft.Office.Interop.Excel.Application myExcelApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
In a testing application its working fine.But its not working in my solution.I have tried to remove all reference file and added once but still not succeed.
The error statement I am getting in second line is "Excel cannot access 'Book1.xls'. The document may be read-only or encrypted."
| | Author: Arun Sahoo 12 Jan 2009 | Member Level: Bronze | Rating:  Points: 5 | Hi Friends, Please someone help me out.I am having following problem.
when I am trying to open existing excel file using following statement
Microsoft.Office.Interop.Excel.Application myExcelApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook excelWorkbook = myExcelApp.Workbooks.Open(workbookPath, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
In a testing application its working fine.But its not working in my solution.I have tried to remove all reference file and added once but still not succeed.
The error statement I am getting in second line is "Excel cannot access 'Book1.xls'. The document may be read-only or encrypted."
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|