How I can save a .xlw format on excel with c# - c#

Well I have a little problem.
I want to save a excel file in C# which format is xlw, but I can`t.
Then I have a idea. I try to save this file in xlsx and after change the format to .xlw, but I don't know how I do this.
Anybody can help me please ?
Thanks!
I try this :
objExcelworkbook.SaveAs("abc.xlw",....);
or
objExcel.ActiveWorkbook.SaveAs("abc.xlw",....);
And the file don't save with this name "abc.xlw".
So, I explain my problem:
I have a mini program that copy different excel files, but the file extension .xlw doesn't copy right. In the other hand, the file extension .xls, save right.

Try this:
objExcelworkbook.SaveAs("abc.xlw",....);
or
objExcel.ActiveWorkbook.SaveAs("abc.xlw",....);

Related

C# File open / convert and save

I am very new to C# and hoping this is a simple question. Not finding what I need on google
I have a file C:\test\losses.csv
That I want to open up then convert to an xlsx file and save in a different directory.
Save to
C:\test\Losses.xlsx
The reason for opening the file is the move command does not convert it to xlsx, unfortunately it keeps the same structure as the csv and is unusable in that format.
File.Copy(#"C:\test\losses.csv", #"C:\test1\Losses.xlsx");
The above code works great but still is a csv file (well really a hybrid of one). That is another SAP story.
Any help will be greatly appreciated. Thanks
File.Copy only copies the file - similar to copying a file in DOS or in windows file explorer.
You'd need to translate your CSV to an XLSX file. The format should be pretty straight-forward, but you'll need to do more research:
Load the CSV as a data table
Use the Excel.XlFileFormat.xlOpenXMLWorkbook class to translate the file.
A different StackOverflow problem addresses how to use the xlOpenXMLWorkbook:
Exporting to .xlsx using Microsoft.Office.Interop.Excel SaveAs Error
Hope this helps. Good luck.

C# Read Data from an URL which downloads a zip file with an CSV file in

I would like to know if there is anyway to use Httprequest or Webclient to read data from an URL (The link is not valid because i changed a little bit because there are private data there).
Like:
https://download.somewhere.com/ReportDownload
The link above is pretty much the format, from the link, you can download a zip file with a CSV file in it. I am wondering if there is a way to use C# to parse out the data instead of downloading it, unzip it and read data from the csv. I would like to get the data and pass that to a variable without any physical download.
If the file provider/site is yours, then yes. You can write a webservice method for that or something like that.
If not, that's not possible. But you can download it to a temporary folder, read it, parse it and delete it aftwerwards.
Hope it helps.

Convert xlsx to xls issue

I am trying to convert a .xlsx file to .xls and it seems to be working fine, however when I open the .xls file I get a warning message "
The file you are trying to open 'filename', is in a different format
than specified by the file extension.
Verify that the file is not corrupted and >from a trusted source before opening the >file. Do you want to open the file now?"....
Everything looks fine when I open it, but I do not understand why this is happening. My next step in this program is to import the data from the xls into SQL, but I am afraid this will cause issues for that.
Here is the line of code where I call the SaveAs method to change the file extension of the file.
wb.SaveAs("filename.xls", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
I initially just had
wb.SaveAs("filename.xls");
and after I got the error I did some more digging around and found the xlOpenXMLWorkbook, but does not seem to help.
Any info that could help me understand why this is happening would be much appreciated.
To save as spreadsheet (OpenXml Format, .xlsx), use XlFileFormat.xlOpenXMLWorkbook:
wb.SaveAs("filename.xlsx", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook);
To save as Excel 1997-2003 format (Biff, .xls), use XlFileFormat.xlExcel8:
wb.SaveAs("filename.xls", FileFormat: Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8);
Make sure you set the appropriate extension (.xlsx or .xls), otherwise, you have the error you described.
See also my answer here Excel Interop Save as is giving compatibility checker in excel 2007

Save .xls file into .txt file in C#.Net

How to save (in fact Save As) .xls file into a text file from C#. I tried File.Copy() but I am unable to see data. I am getting some special characters in the text file.
Any help would be appreciated.
You should use the Microsoft.Office.Tools.Excel.Workbook.SaveAs() method

load excel template file and write data to cell?

I have a excel template file (C:\Report\Template\abc.xls).
I need to write a C# console application to do following,
copy the abc.xls file from Template folder and save the same template with different name and different folder "Data" ((C:\Report\Data\new_abc.xls)
load the "new_abc.xls" file into memory and write data (comes from database) to it's specific cell (for example i want to write in cell H17)
Please let me suggest or give me link or code to do this. Thanks!
Copying files is easily done with File.Copy. Simply pass in the source path from which to copy and the destination path to copy to as strings.
Take a look at the Microsoft.Office.Interop.Excel classes for manipulating Excel workbooks. Here's a good code sample to get you started. Also this is another overview.

Categories

Resources