Automate opening and formatting of csv file in unix - excel

My requirement is as follows:
Open an input csv file in spreadsheet in unix (like ooffice)
Post process the excel for following requirements:
Post process a column such that fields with number less that 0 appear as red
Put filters on top of each relevant columns (As we can do in Microsoft excel)
save the file in .xls (or any other format) such that when opened in microsoft excel, the data formatting is not lost.
The above automation requirement is part of my flow. Though I am familiar with scripting, I have never worked on such requirement.
Will really appreciate your help.

Here is a solution using csv2odf that should get the result you want:
Create a spreadsheet template in Excel or OpenOffice with these specifications:
Insert column titles with the same number of columns as the csv. (If you want to use titles from the csv file, add the -H option to the command below.)
Add one sample row of data. Use dummy numbers where numbers will go and dummy text where text will go. Format the text/numbers however you want, including conditional formatting to make negative numbers red.
Save the template as xlsx or ods (xls will not work).
Run this command:
csv2odf yourdata.csv yourtemplate.xlsx output.xlsx
Your data will be inserted into the template and the formatting will be duplicated on each row.

Related

Including format instructions in CSV?

I have to write data in a csv format, but some of the users will edit that in excel and those have been complaining about the lack of cell formatting. Is there any way to include some instructions on how excel should format the cells, e.g. the same way you can tell excel the separator with an initial line with SEP=,?

How to format a formula in Microsoft Excel to be in percentage format DIRECTLY in the CSV source file

The problem:
For example, my CSV data is like so: ['=B3/B5'] which displays 0.1 in my Excel sheet but I need it to produce 10%.
I need to be able to fix this from the CSV source data because I'm exporting a CSV file from my website so that means no excel formatting to percentages as I need it to work out of the box for users.
Preferably the solution should be able to support Excel 2007. Google Sheets has a =to_percent(B3/B5) function which works well but I need the equivalent for Excel 2007.
I had a look at this answer: https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-value-as-a-string
But doesn't seem to directly address the problem.
You could use =B3/B5*100&"%"
Note that this will not be saved as a number (ex. 22.1%) rather as text, because you can't use number formats in a CSV file.

Automatically convert csv file into Excel table?

I generate some csv files using a script. Next I manually convert those csv files into excel tables using the import wizard in excel based on:
https://www.youtube.com/watch?v=z5Pxil4jVO4
Is it possible to do this automatically - e.g. by calling an excel importer from command line - so I don't need to open excel and do all the manual work?
I can open the csv file directly in Excel but its not formatted as a table. E.g. this csv file:
a,b,c
a,b,c
results in this Excel sheet:
I would like each letter to be in a separate column.
I have looked at this:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/370ee470-f2cd-4f30-a167-b106dd51d47a/powershell-convert-csv-to-xlsx?forum=winserverpowershell
but its an awful lot of boiler plate code from create a simple table.
Add an extra line to your CSV file to tell Excel what the seperator is. Add the following line to the top of your CSV file:
sep=,
The easiest way, without close and edit your file - you can choose which separator you want in Excel 2010-2016 go to DATA, Text To Columns, choose Delimited, then choose your separator Comma (or other) and you will see changes immediately in the "Data preview", then click FInish.
Once you have the format you wanted, you simply save the document and it will be permanent.

Excel Save CSV without blanks

I have an Excel spreadsheet that generates CSV scripts used in an application. The scripts must be in a very specific format, and I save a master in XLSX format with protected sheets and data validation to save the CSVs from rather than directly edit the CSVs, as directly editing the CSVs can lead to mistakes.
The issue is that the scripts can be of nearly any length. The left column of each line can only be one of a certain set of values, and the last line has to say "END". The only way I can do this without VBA is the following formula in the A column, from row 7 (the first 6 are header information) to row 1048576 (last Excel row) and protect the sheet with column A locked:
=IF(AND(ISBLANK(B368),NOT(ISBLANK(B367))),"END",IF(ISBLANK(B368),"",A367))
This makes the last row say "END" in column A, and all rows after blank, which is what is desired. The problem is that now when the CSV file is saved, it will always have 1048576 rows, with all the bottom rows containing the delimiters ",,,," . This won't work, the CSV file needs to stop after the "END" row. Is there a way to write the formula that will cause Excel to ignore the cells which evaluate to blank when saving to CSV or an alternate way to save to CSV in Excel that will ignore all the rows that evaluate to blank?
Note: I have a solution in VBA already that I can use on my own machine (it copies the data up to "END", pastes in a new sheet in text only format, then saves as CSV with the name of the original worksheet). I want to share this sheet, however, and getting around the security constraints to share macros at my company is a pain. So I'm looking for a way this might be done without Macros, if it's possible at all.
In looking for an answer I found this link, which is similar, but not the same:
Saving Excel data as csv with VBA - removing blank rows at end of file to save
As the "blanks" I have are active rows because they contain formulas, this method will not work.
Manually deleting the rows / columns will work to reset the size, as GSerg noted in the other question. Alternatively, also as suggested by GSserg, you can copy the data to a new sheet before saving.
Otherwise, an easy fix might be to create a small post-excel / pre-processing script - perhaps using a batch file - Batch / Find And Edit Lines in TXT file - or a similar solution in any small scripting language to remove the extra rows.

Excel and Tab Delimited Files Question

I am encountering what I believe to be a strange issue with Excel (in this case, Excel 2007, but maybe also Excel 2003, but don't have access to it as I write this).
I can reliably convert some server data over into a tab-delimited format (been doing this for years) and then open it using Excel - no issue.
However, what seems to be happening is if I have an html <table> inside one of the fields, it looks like Excel 2007 thinks it should be converting the table into rows and columns inside Excel (not what I want). As you might imagine, this throws off the entire spreadsheet.
So question is, is there any way to set up excel to NOT do this (perhaps some setting in Excel that pertains to reading tab delimited files), or am I missing something?
Thanks.
Save your file as .txt
Now open the file in excel using Drag and Drop (rather than double clicking your hookey .xls)
Slightly more work to open the file, but your tab text formatting will now be respected.
When you open the tab-delimited file, you are shown an import mapping dialog that lets you pick each columns' data type (date, text, currency, etc.). For the columns that have HTML data present, choose text. This will tell it basically to import as-is and not try to automatically parse the data into a derived format.
Excel 2003 does the same. I don't think there is a way to do it with a config because Excel finds delimiters in the html table and breaks the html in cells and columns as it does for the other columns.
If the column containing html is always the same, you can use JYelton suggestion of renaming the file as csv and record a small VBA macro to load the file selecting automatically the html column as text in the import mapping dialog and you load the file calling the macro instead of double-clicking on the file.
If nothing else, import it into OpenOffice.org Calc, save as an .xls file, then open in Excel.

Resources