473,406 Members | 2,273 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,406 software developers and data experts.

Saving Excel File

16
Hello friends!!!

I made a prog. to make the excel. It is running well but when it saves the excel file it open the save dialog box to save the file becasue I am using SAVE function here instead of SAVE AS. So pls can anyone tell me how to use SAVE AS function in it so that i could give File name from my Programe. If I am using "Save As" Function then I am getting Error.

My be I am not giving appropriate parameters.

ERROR IS :

[ No overload for method 'SaveAs' takes '1' argument]

so pls help me here: My code is below:

protected void Button1_Click(object sender, EventArgs e)
{
Excel.Application xapp;
Excel.Workbook xwb;
Excel.Worksheet xws;
xapp = new Excel.Application();
xapp.Visible = true;
xwb = (Excel.Workbook)(xapp.Workbooks.Add(1));
xws = (Excel.Worksheet)xwb.ActiveSheet;
xws.Cells[1, 1] = "deepak";
xapp.Visible = true;
xapp.UserControl = true;
//xapp.Save(0); //this is working fine but showing save as DIALOG BOX
xws.SaveAs("c:\\temp\\MyFile.xls"); //this is giving me error
}

Thanks in advance!!!!!!!!!!
Mar 30 '07 #1
2 3804
Hello!!
The problem is that SaveAs function, unlike the vb.net, in c# has more parameters.
Here is a piece of code that is working on my machine.

Expand|Select|Wrap|Line Numbers
  1. Excel.Application app;
  2.             Excel.Workbook book;
  3.             Excel.Worksheet  sheet;
  4.             Excel.Range range;
  5.  
  6.             System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
  7.             app = new Excel.Application();
  8.             app.DisplayAlerts = false;
  9.             app.Visible = true;
  10.  
  11.             book  = app.Workbooks.Add(@"C:\template.xlt");
  12.             sheet = (Excel.Worksheet)book.Worksheets[1];
  13.             app.Visible = true;
  14.             sheet.Name = "1245";
  15.             range = sheet.get_Range("A1","J100");
  16.             range.Value2 = "test";
  17.  
  18.  
  19.  
  20.             while(Marshal.ReleaseComObject(sheet)>0);
  21.             sheet = null;
  22.              book.SaveAs(@"C:\rezult.xls",Excel.XlFileFormat.xlExcel9795, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange , Excel.XlSaveConflictResolution.xlLocalSessionChanges, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false);
  23.             book.Close(false,System.Type.Missing, System.Type.Missing);
  24.             while(Marshal.ReleaseComObject(book)>0); book = null;
  25.  
  26.             app.Quit();
  27.             while(Marshal.ReleaseComObject(app)>0);   app=null;
  28.  
  29.             System.GC.Collect();
  30.             System.GC.WaitForPendingFinalizers();
Hope this wil hepl.
Apr 2 '07 #2
DPK
16
Ofcourse Friend It did very much help.....
thank you very very much...!!!!!!!
:-)

Hello!!
The problem is that SaveAs function, unlike the vb.net, in c# has more parameters.
Here is a piece of code that is working on my machine.

Expand|Select|Wrap|Line Numbers
  1. Excel.Application app;
  2.             Excel.Workbook book;
  3.             Excel.Worksheet  sheet;
  4.             Excel.Range range;
  5.  
  6.             System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
  7.             app = new Excel.Application();
  8.             app.DisplayAlerts = false;
  9.             app.Visible = true;
  10.  
  11.             book  = app.Workbooks.Add(@"C:\template.xlt");
  12.             sheet = (Excel.Worksheet)book.Worksheets[1];
  13.             app.Visible = true;
  14.             sheet.Name = "1245";
  15.             range = sheet.get_Range("A1","J100");
  16.             range.Value2 = "test";
  17.  
  18.  
  19.  
  20.             while(Marshal.ReleaseComObject(sheet)>0);
  21.             sheet = null;
  22.              book.SaveAs(@"C:\rezult.xls",Excel.XlFileFormat.xlExcel9795, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, false, Excel.XlSaveAsAccessMode.xlNoChange , Excel.XlSaveConflictResolution.xlLocalSessionChanges, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false);
  23.             book.Close(false,System.Type.Missing, System.Type.Missing);
  24.             while(Marshal.ReleaseComObject(book)>0); book = null;
  25.  
  26.             app.Quit();
  27.             while(Marshal.ReleaseComObject(app)>0);   app=null;
  28.  
  29.             System.GC.Collect();
  30.             System.GC.WaitForPendingFinalizers();
Hope this wil hepl.
Apr 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Vikram | last post by:
Hi, Given below is my task. An user can open the xls file from my website (loaded on the top frame). After filling the Excel, he can click a send button at the bottom frame. By clicking the...
1
by: Helmut Blass | last post by:
hi Access-freaks, in MS Access, I generate an Excel file where the user should have the possibility to determine the excel file name by file dialog. so I use the following command: ...
0
by: dd | last post by:
I am kind of puzzled with this problem. I am trying to open an xls file from C# and then save it as text or comma delimited. Here is the code: Excel.ApplicationClass oExcelApp = new...
7
by: alwayssmiling | last post by:
Hi frends, In my application, a class supports backend processing. In this class im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file...
1
by: NBKMNDN | last post by:
Hi frends, In my C# application im creating a new excel sheet and im inserting some data into this excel sheet, and im trying to save the file with the help of method SAVE AS. But it doesnot...
0
by: Speilman_54 | last post by:
Hi, I'm converting an excel Macro into visual basic 2005 express, as I don't have a copy of VB 6 and trying to make and executable from it, I know this version doesn't have the save file as .exe,...
6
by: Karl | last post by:
Hi all, It may seem like a rather odd request (or not) but I would like to be able to create a file (doc, jpg, xls or one of many other files that can be automated) on a website and stream it to...
0
by: veer | last post by:
hello expert i am facing a probleum of saving the out put in excel sheet actually i have two buttons on my vb form i,e merge entery and merge verify and when i execute my program one by one...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
10
by: N2Deep | last post by:
I have a macro that does a few things to an Excel workbook and then saves, and closes to an Excel workbook. I now want to save, close the Excel workbook as a text (tab delimited .txt) file. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.