How to force excel not to drop rows when opening csv-file? - excel

Background:
We have a web application where the user can export orders in csv-format. For users with Microsoft Excel installed it's the default program. They simply click 'Open' after the file is downloaded. Users mainly use Internet Explorer, Firefox and Chrome. No difference in behaviour.
The problem:
If the user just open the csv-file (from browser or explorer) the file is opened by Excel and data is loaded automagically. But sometimes rows are just missing. Gone. No exception, no message, nothing.
The data is there, if you open the file with notepad you'll see it.
(I suspect it has something to do with special chars, quotes, commas etc but I can't find a root cause for this)
How to make it work:
If you save the file to disk, open excel and selects File -> Open -> Format: Textfiles (*.prn, *.txt, *.csv, *.skv) -> Open excel will launch a import wizard and everything will work perfectly.
Is there anything I can do with the export-file to either force the Import Wizard or just tell Excel not to exclude our critical order information without warning?

I think I've found the cause of this. It seems to be due to regional settings as described in this post and sugesstions from superuser.com
I solved it by wrapping all fields except numbers with quotes and now it works just fine.

Make sure that you use a consistent delimiter scheme across all lines in the file. For example, check if you have both \n and \r\n sequences as line delimiters.

Related

Excel hangs/crashes while updating external link at file opening

I encountered this weird ass and funny error.
I built a file for data ETL. This one takes in various .csv files, combines them and export new .csv files using VBA. The file is originally named as "xxx Modelling ETL.xlsm". It could be opened normally till one day it hangs or crashes while trying to recalculating something (may be the underground query).
After hours of struggling, I opened the file as a copy (under a new name of Copy of ...). Strangely it ran smoothly, no crash or hang. Then I try rename it by remove the "Copy of" part, then the error occurs again.
I want to share this as there could be someone has the same problem, or someone who could shed some light on this black magic thing.
Some solutions:
Rename the file or move it to local drive instead of Onedrive makes thing works normally again.
Open Trust Center, disable Macro with notification, Trusted Locations, and Trusted Documents. Enable them for specific files when open, not for all.

Microsof Excel 2016 Unicode (UTF-8) does not work

I searched all around internet how to save CVS file as Unicode (UTF-8), but it still does not work, whenever i save, and open the file, there is ????? instead of letter that are UTF-8.
Has anyone ever had this issue? how can i solve this?
This has been annoying short coming of Excel for a long time.
A way to work around this issue, is to do the following:
Save as... Unicode text (*.txt). Make sure to keep the extension as txt (or at least not csv). It will be saved with tabs instead of commas separating the columns.
Open the document. You will be prompted with an import wizard, like so:
For File origin, choose 65001: Unicode (UTF-8)
For the rest of the options, choose the common sense options.
You will have your document back, ready to edit, with the proper unicode text intact.

Updating "text connection" path using provided string and preserve text to column settings

I have an Excel file with several sheets connected to many external csv files. This has worked fine for now working on my own, but now I'd like to be able to move the Excel file and/or csv files, or hand them off to someone else, and not break the connections.
The method here works for updating the file name based on a provided string:
Editing "text connection" paths
...but it doesn't preserve the text to columns settings after updating the path. Since I'm dealing with csvs, I need the import to come in as comma delimited. Since I'm dealing with a lot of connections in a single file, I'd also like to be able to let the user define a single path somewhere, and have it automatically use that path to find the files.

File that normally opens our application, but will fall back to Excel

Our application exports snippets of databases in XLSX format. We wrote our own code on top of System.Packaging as it is many (many!) times faster than using the Excel objects.
Right now we save these files with a .xlsx format, and that works OK. However, it would be much nicer if double-clicking one of these opened our app instead, but failed back to Excel on machines without it.
I know that SpreadsheetML has a feature to do this. If you insert this near the top of the file:
<?mso-application progid=""Excel.Sheet""?>
some sort of magic occurs that causes Excel to open on Win machines. While this might work in SML files, it does not appear to work in "real" xlsx files - I tried adding this line to various parts of the workbook structure but it remained unrecognized.
So is there a similar mechanism we can use in "true" XLSX files generated by System.Packaging? Or some other Windows mechanism we should use in these situations?

Matlab: open files 'outside Matlab' by default

I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (i.e., by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.
The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.
Thanks.
When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport.
In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction.
However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:
% this setup will not allow users to override the default EXTread behavior
If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:
edit finfo.m (Now save a copy to the current folder)
Add these lines after the loop that defines the openAction (in my version, around line 85):
if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
openAction = 'winopen';
end
From the folder containing your edited finfo.m, type which finfo -all. You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.
I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.
You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx. That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.

Resources