Opening an Excel File in Notepad gives un related data - excel

I am downloading an excel attachment from an email using a tool and converting that file to CSV Using VB Script. The problem I am facing is, after converting the file to CSV, when I try to open the file using notepad, it shows boxes instead of the correct data. But the same file if opened using an excel then it returns the correct data.
But if I create a mew CSV file and open it with notepad I am not facing this problem. kindly help me !!!

Without looking at your script, I would guess that the file is simply renamed to a .csv file - but not actually converted! This way, you would end up seeing the binary data in Notepad.
Try to open the original Excel file in Excel - and there save it as .csv. This will surely work, i.e. you'll see the data in Notepad.
If that does not help, please share your script.

Related

EPPlus Adding VBA Code Corrupts resulting xlsx file

I'm creating an excel file using EPPlus from a datatable and saving it to a file, all fairly standard. This works without any hassles. However, if I create a vba project, and add any vba code, the resulting .xlsx file is suddenly corrupted. When try and open it with 2013, you get the standard error.
"Excel cannot open the file 'xyz.xlsx' because the file format or file
extension is not valid. Verify that the file extension matches the
format of the file.
If I change the extension to .xls, the file opens ok, and the script runs fine. I'm on the latest beta of Epplus (4.5.0.1). Should I just change the file extension and stick to .xls, or is there something amiss?
ExcelPackage.Workbook.CreateVBAProject()
ExcelPackage.Workbook.CodeModule.Code = "'Script is here"
Dim FInfo as new FileInfo("C:\Myfiles\ThisFile.xlsx")
ExcelPackage.SaveAs(FInfo)
You can not add VBA code to XLSX file format.
Take a look at here
.xlsx:
The default XML-based file format for Excel 2007-2013. Cannot store
Microsoft Visual Basic for Applications (VBA) macro code or Microsoft
Office Excel 4.0 macro sheets (.xlm).
Also take a look at here
to see differences between different formats:
XLSM If you include VBA macros in your XLSX file, you will be asked to
change the file extension to XLSM. Only that way you can save your
macro within the Excel file (there are other file types possible, e.g.
XLSB – but you can’t use XLSX for VBA macros)
Save your file as XLSM and it should work.

What is the difference between .xls file exported with Display tag and created with Excel

I use Display tag in Struts 1.3 to export a table to .xls file.I can export this without any problem and I can open this file with a text editor and view or edit.
<display:setProperty name="export.excel.filename" value="Export.xls"/>
Then created .xls file in Excel 2003 and try to edit it with text editor, but it's binary file.
The file size created with Excel is much bigger comparing to exported file.
Furthermore, When I try to open the exported .xls file in Excel 2013 it gives following popup,
"The file format and extension of 'Export.xls' don't match.
The file could be corrupted or unsafe.
Unless you trust its source ,don't open it.
Do you want to open it anyway ? (Yes/No/Help)"
What is the reason for this?
I found the reason behind this.The exported Excel(.xls) from displaytag is text-based excel and not a POI-based excel.But Excel application creates binary .xls file.

Converting .csv file to text file using Excel macro

Would like to ask if how to convert a .csv file generated from macro to .txt file?
I have this Excel macro that gathers data from the website and create a table and output it to a .csv file, but for some reason I wasn't able to copy its contents to an existing .csv file as it returned special characters instead of the correct output.
Please help me, with the program I am currently doing.
A csv file is a text file. U can just change the extension like this
Name "C:\\**\\a.csv" As "C:\\**\\a.txt"

Why does opening a CSV file in Excel break my Highcharts chart?

I'm working on using CSV files to create Highcharts – but running into an odd problem: when Excel 'touches' a CSV file, the chart breaks immediately. Here's the simplest example:
Highcharts online documentation has a handy example of a bar chart generated from a CSV file: http://www.highcharts.com/studies/data-from-csv.htm
The data underlying this chart can be downloaded from: http://www.highcharts.com/studies/data.csv
But here's the odd thing. If I download those files, and recreate the chart on my own web server, everything works fine... until I open the data.csv file in Excel, then save it. This breaks the Highchart immediately, even if no changes are made to the underlying data. No error messages are thrown up in the console – the chart simply goes blank as soon as Excel makes a save.
I know what you're thinking – "this moron is saving a CSV file as a .xslx, then wondering why his chart breaks." But that's not what's happening – using the 'Save As... .csv' option in Excel also breaks the chart immediately.
Here's the content of the CSV file before I open it in Excel (cut and pasted from TextEdit):
Categories,Apples,Pears,Oranges,Bananas
John,8,4,6,5
Jane,3,4,2,3
Joe,86,76,79,77
Janet,3,16,13,15
And here's the content of the CSV file after opening it in Excel:
Categories,Apples,Pears,Oranges,Bananas
John,8,4,6,5
Jane,3,4,2,3
Joe,86,76,79,77
Janet,3,16,13,15
To my eyes, those are the same file! And yet the first one renders perfectly, the second (which has been saved by Excel) creates an invisible chart.
Any help greatly appreciated. I'm using Excel 2008 for Mac, if that's relevant. Thanks in advance...
Seems the solution was to save:
the CSV file as a 'Windows comma separated CSV'

Excel xlsx file saving as CSV file - Korean and Japanese cracking badly

I am trying to make a CSV file from an Excel file. It has English, Korean and Japanese inputs. Right now it's saved as file.xlsx.
But when I try to save-as CSV through Excel as file.csv, all the Korean and Japanese inputs turn into question marks (???????)
I tried importing into Google Spreadsheets and exporting out as csv from there (from reading some other solutions) but it still turns into question marks.
I tried building a CSV file from scratch and just copying/pasting values from the Excel file into the CSV, but after I save it as CSV, the characters always crack.
Does anybody know how to work-around this? Thank you
I don't know that there IS an answer for this. CSV has no encoding, so it gets lost when you save in that format.
I tried, as a test, saving Chinese characters as a Unicode Text file, and believe it or not, that worked. So you may be able to do that, and simply change the filename to CSV. Assuming for some reason you NEED the filename to be CSV.
EDIT: I just ran addional testing on this. I was able to reimport the TXT file with either TXT or CSV extension, and the characters stayed just fine. So I think Unicode text is your answer.
Simply opening a CSV file in Excel only works when default assumptions hold. You may be writing the CSV correctly but not validating it properly.
It is more reliable to open a blank worksheet and then use Data Import. The encoding of the CSV file is one of the parameters you can specify.
To fully retain the characters while saving it on a CSV format and to somehow be able to import/re-use the data in the future.
You can follow these steps.
In Microsoft Excel, open the *.xlsx file.
Select Menu | Save As.
Enter any name for your file.
Under "Save as type," select Unicode Text.
Click Save.
Open your saved file in Microsoft Notepad.
Replace all tab characters with commas (",").
Select a tab character (select and copy the space between two column headers)
Open the "Find and Replace" window (Press Ctrl+H) and replace all tab characters with comma .
Click Save As.
Name the file, and change the Encoding: to UTF-8.
Change the file extension from .txt to .csv.
Click Save.
Open the .csv file in Excel to view your data.
Had the same issue. the below article shows the workaround in details:
https://help.salesforce.com/articleView?id=000003837&type=1
However, i decided to go with LibreOffice Calc, as it requires less steps to achieve the desired outcome. While exporting, you get to select charecter set, field delimiter and text decimeter.
For all other tasks, i prefer Excel.
Download and install Unicode CSV Addin for excel.
Save the csv from the new "Unicode CSV" menu as shown in picture
below.

Resources