Including format instructions in CSV? - excel

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=,?

Related

both read and write excel formats in R

I'm trying to read an excel file including formatting (cell and text colour, bold, ...) to R, do some editings in the data, and then write it back to excel, including the original formatting. So far, I found R packages to write excel files including formating (openxlsx, xlsx), and also a package which reads excel format (tidyxl). However, I didn't find an easy way to write an excel file with the same formatting that has been read by the R function.
I.e.: the way that tidyxl gathers the format data in an R object is totally different than how openxlsx or xlsx writes it to excel format.
I wonder if anyone knows of something or developed any easy function for this.

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.

Perl - Reformat a column in Excel

Using some combination of Win32::OLE, ParseExcel, WriteExcel...I want to be able to change the formatting of all of the cells in a column (or multiple columns, based on a condition) to be a custom date format, such as "yyyy-mm-dd h".
I have been able to use Win32::OLE to do a find and replace on an Excel file that I have open, but I am not sure the best way to reformat an entire column of cells. I imagine it will be something along the lines of parsing the file with ParseExcel, and using WriteExcel to overwrite the file after changing the format somehow.
Any advice would be greatly appreciated, cheers!
Don't overwrite, copy to a new name (then you can compare, and the process is reversable).
You would essentially copy all the cells, modifying only the ones you need to format change.
Excel Format Info - many examples for formatting time

Automate opening and formatting of csv file in unix

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.

Programmatically format a date in an excel sheet using Office Open Xml SDK

I'm building an Excel xlsx spreadsheet using the office open XML SDK. I can add dates to the sheet by converting them to their "AO" date representation and setting the Cell Value to number. I can't, however, figure out how to add the dd-mm-yy formatting to the cell.
I've seen a lot of complicated examples where you have to create a stylesheet from scratch, add the format to it and then reference that format, but I figure there must be an easier way. I'm creating my sheet from a template, and Excel already has builtin formats/styles. IMO I should be able to just load the stylesheet from the excel file I'm using as a template and then apply the format. Can't figure out how to do it though.
If you're creating an xlsx from scratch you can't avoid creating the style sheet. You minimally need a style sheet and cell format element. The cell format element can reference a built-in date format in which case you can avoid the custom number format, but if you want a date format that isn't built-in you need a number format element too.
If you're creating an xlsx from a template xlsx, then you can reference a cell format that's already defined, but it can be very sensitive since the references are based only on index, so you are safer looking through the defined cell formats to find the one that matches the date format you want as opposed to hard-coding the cell format index.
Try this - I used it when I was trying to make my own number formats. It's a good example:
Advanced Styling in Excel OpenXML
You will still have to create a style sheet but this is a very good place to start. He has quite a few styles in his as he demonstrates what can be done. Your style sheet could be lots simpler if you only want the one format.
Also have a quick look at the list in this post. Your format may be built into Excel already.
Built in Styles for Excel

Resources