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

C# Saves two copies of a file!

JM
Hi!

I've worked hard to get my data into Excel from a bunch of text files. I've
opened Excel and dumped the data in. I want to save the workbook/spreadsheet
but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and
path. You know the usual. I don't want this. I want to automate the entire
process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I
get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM
Nov 17 '05 #1
4 4933
DisplayAlerts = false;

You should also use the SaveAs() method for files previously unsaved and set
Overwrite to true.

Dale Preston

"JM" <JM@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi!

I've worked hard to get my data into Excel from a bunch of text files. I've opened Excel and dumped the data in. I want to save the workbook/spreadsheet but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and
path. You know the usual. I don't want this. I want to automate the entire process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I
get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM

Nov 17 '05 #2
JM
Here is what I used. But the compiler complains

excel.ActiveWorkbook.SaveAs("c:\\MyWorkbook.xml",e xcel.XlFileFormat.xlXMLSpreadsheet,
Type.Missing, Type.Missing,Type.Missing, Type.Missing,
excel.XlSaveAsAccessMode.xlNoChange,
Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing);

excel.XlSaveAsAccessMode.xlNoChange & excel.XlFileFormat.xlXMLSpreadsheet

Any ideas as to what these constant values are? I actually want to save a
normal excel file too!

"Dale Preston" wrote:
DisplayAlerts = false;

You should also use the SaveAs() method for files previously unsaved and set
Overwrite to true.

Dale Preston

"JM" <JM@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi!

I've worked hard to get my data into Excel from a bunch of text files.

I've
opened Excel and dumped the data in. I want to save the

workbook/spreadsheet
but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and
path. You know the usual. I don't want this. I want to automate the

entire
process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I
get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM


Nov 17 '05 #3
JM
Never mind! I managed to figure out how to get the constants to work!

Here is an example!

string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";

excel.ActiveWorkbook.SaveAs("c:\\" + ExcelFile,
Microsoft.Office.Interop.Excel.XlFileFormat.xlWork bookNormal, Type.Missing,
Type.Missing,Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlNoChange,Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

"Dale Preston" wrote:
DisplayAlerts = false;

You should also use the SaveAs() method for files previously unsaved and set
Overwrite to true.

Dale Preston

"JM" <JM@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi!

I've worked hard to get my data into Excel from a bunch of text files.

I've
opened Excel and dumped the data in. I want to save the

workbook/spreadsheet
but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and
path. You know the usual. I don't want this. I want to automate the

entire
process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I
get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM


Nov 17 '05 #4
I'm glad you got it. It saves me from digging deep into my archives for
when I last worked out saving Excel files from Visual Basic.

Dale

"JM" <JM@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Never mind! I managed to figure out how to get the constants to work!

Here is an example!

string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";

excel.ActiveWorkbook.SaveAs("c:\\" + ExcelFile,
Microsoft.Office.Interop.Excel.XlFileFormat.xlWork bookNormal, Type.Missing, Type.Missing,Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode. xlNoChange,Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);

"Dale Preston" wrote:
DisplayAlerts = false;

You should also use the SaveAs() method for files previously unsaved and set Overwrite to true.

Dale Preston

"JM" <JM@discussions.microsoft.com> wrote in message
news:6F**********************************@microsof t.com...
Hi!

I've worked hard to get my data into Excel from a bunch of text files.

I've
opened Excel and dumped the data in. I want to save the

workbook/spreadsheet
but have not set a file name yet in the coding.

Running the below code I get a Dialog box that prompts for a file name and path. You know the usual. I don't want this. I want to automate the

entire
process. I want to create a filename that have MVC <Date>.xls.

If I cancel the dialog box I get an exception. If I put in a file name I get my file (named as above) but also an additional file book1.xls for
example.

Is there a way to supress the dialog box and just save the file in the
naming convention that I want???

//Set default path and filename.
excel.DefaultFilePath = (@"C:\");
DateTime dtCurrTime = DateTime.Now;
string ExcelFile = "MVC " + dtCurrTime.ToShortDateString() + ".xls";
excel.Save(ExcelFile);
excel.Quit(); // Close Excel

Thanks JM


Nov 17 '05 #5

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

Similar topics

9
by: Henning Kage | last post by:
I'm using Python only for some months now and I'm wondering, whether such assignments as above are creating bitwise copies of an object or just recieve a reference. That means I wanted to know,...
8
by: qazmlp | last post by:
As I understand, there will be 100 copies of "myTestClass", when CLASSNAME is declared as below: #define CLASSNAME "myTestClass" But, there will be only 1 copy of "myTestClass", when CLASSNAME...
1
by: jsnX | last post by:
hi, i would like to make some code that operates on sets of points - does convex hulls and other operations. but it looks like i will need a lot of pointless object copies: ...
3
by: Gary Ferland | last post by:
Greetings, I have a large console C code that is compiled every night by the master machine that hosts the source. I have a number of slave machines that then make copies of the executable on...
8
by: Hank Reed | last post by:
Hello, I have searched through dozens of old responses to this question but have been unable to make it work in my situation. I'm using Access 2000 We have a very old sticker printer on a...
1
by: brian.gabriel | last post by:
I have a ASP.Net application written in VB.Net, I have a file import function that imports a file then moves the file to an archive. The problem is that the File.Move statement copies the file,...
8
by: Philip Wagenaar | last post by:
I need to send printjobs to a printqueue under diffrent usernames. The printsoftware on the queue is not very 'secure' so I can create a user on 1 system and send a printjob under it's name to the...
4
by: Adam - Regus | last post by:
I'm trying to create a button that prints 2 copies of a form. Using the wizard, I created a button that prints one automatically, using the following code: End Sub Private Sub...
5
by: Defected | last post by:
Hi All, I have problem whit this program, because the output file print copies but only at the end of file, and the file does not have two copies of the same element. Example of elements in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.