i created an application that takes the excell output of a table.There are long numbers in table cell.When i took the output the cells that have long numbers are seen like that 1234+E34.how can i fix that?Thanks for advance...
So you're not actually writing an Excel file: It looks as though you're writing an HTML file but sending headers to the browser telling it that it's an xls file...
Excel can then identify that HTML, and parse it into a structure that it can display.
You have a couple of alternatives.
The first is to create a genuine xls file rather than trying to con the browser and Excel. The Second option: instead of writing the value as
12345678901234567890
write it as
="12345678901234567890"
This will display in excel as "12345678901234567890" (with Quotes)
To avoid this, Use intval(12345678901234567890) in php, This forces Excel to treat this number as an integer
Related
Recently I mastered fgetcsv in the hope of writing an array to a file so that I could later open it via Excel, there was no problem with it. Everything turned out ok. But, as far as I understand, there can not be done so to automatically push apart the cells to the length of the string (maybe looked bad)
Now it is written like this:
I want to know are there are any libraries, so that the cells length is set to the length of the string written to the cell?
It is necessary that it was like this:
Or maybe there is another approach? For example, manually in Excel to convert all at once so?
I will be grateful for any help, thanks!
CSV files doesn't have any cell length defintion
They are text files, with Comma Seperated Values (CSV ...)
xlsx files however DO hold such a feature
They are basically xml zipped
You can either look for a php excel library with a function ready or parse the XML yourself...
XML sturcture is reffred to here
Looking for a clear description of Excel's .xlsx XML format
Worksheets("Sheet1").Columns("A:D").AutoFit
I need to export the output of php script to xls or csv file. Output file must be formatted (font size, font weight, borders etc).
I have two options:
content variable as string with html tags (formatted text)
an array with data ready to be formatted
The easiest way I think is to export variable containing html code strict to xls file which I just did. The only problem is when I download xls file and open it, Excel alerts me that opened file format is different that file extension.
Headers in my php script:
header("Content-Type: application/xmls.ms-excel");
header("Content-Disposition: attachment;filename=test.xls");
header("Content-Transfer-Encoding: binary");
Charset is set to UTF-8.
Also I'm able to use array variable with data that I need to put in cells, but:
I don't know how to format cells (fonts, borders etc)
I don't know how to put data in exact cell
I'm not able to use PEAR and Spreadsheet_Excel_Writer
Any further help will be appreciated.
Just dumping HTML out isn't going to work, unfortunately. If you really need the spreadsheet to be formatted, CSV isn't an option since it doesn't store formatting information.
That only leaves XLS as a file format, which is a complicated binary format. Trying to export to it directly is impractical, which is why a few PHP libraries have been written to take care of this for you. I was recently bonked over the head with PHPExcel, which is supposedly not all that difficult to use. My experience with Excel exporters is that they definitely do have a learning curve to them however.
You don't say why you can't use PEAR, but if you're unable to use any external libraries at all, then you're probably out of luck.
I am looking for a way to open a CSV file, that was created with a PHP script, in Excel - in such a way that Excel knows how to parse the file. Currently when i double click on a CSV file created with PHP, Excel opens the content in a single column so it does not parse each line. Also, if i do CTRL-O in Excel and select the CSV file to be opened, Excel launches a wizard where i am able to select parsing and encoding option.
Are there any 'headers' or flag characters that i could prepend to the CSV output in PHP to let Excel know how to open a file? I know, for example, that in order for Excel to handle UTF8 encoding, a U+FEFF character needs to be included as the first character in the CSV file, so maybe there is something similar for parsing?
Thanks.
Beware that depending on your xcel version you will or will not have the csv options dialog in Excel when opening direclty the csv file.
latest versions of Excel I've tested needs a special menu usage to get this dialog.
So you should provides what Excels wants.
And what he wants is a tab-separated csv (not comas, funny enough when he save a csv file he use comas but not in his auto-import), without " and without carriage returns in cells, and not in utf8.
Some says he need some sort of UTF16, I can't remember exactly, certainly the UTF-32LE BOM cited by Mark Baker. You will certainly have to transcode your chars.
Then do not forget to set tes text/csv mime type header.
When I see this broken auto-import csv without dialog of the new Excel I wonder if they didn't want to avoid complelty csv usage :-)
Ho, and I saw somewhere in past that there some mysterious formating commands you can use in an pure HTML table export that Excel will understand really better than the csv format.
You should search a lttle about it, maybe really simplier.
I am generating a simple csv file using php. The file contains some user's personal data.
When I open the generated file in office, the addresses are not displayed in full height. I have to double click on the cell for the address to be shown fully (in full width and height) otherwise I can only see the first word/number of the address.
Also, I have date of births displayed as ######, I have to expand the whole column to see them fully.
This doesn't happen in open office.
Is there any way to force MS Office to show all fields in full? Because otherwise it'll be to confusing for the people who will use (Hey where are all the details!:)
Thanks :)
I don't think you can "format" your sheets with CSV. You will have to produce some other file format that Excel understands. I would suggest XML which is really easy to generate.
Just make a sample sheet with the data you want, save it as XML and you'll see how your file should be generated.
Or you could use some ready-made PHP solution for writing excel files if you can't be bothered with analysing the XML file.
you could try the auto-size columns feature.
This is a UI issue with how Excel works, you can't force Excel or anything else how they handle it.
The quickest work around is to perhaps create an XLS file that runs a macro to retrieve the CVS file and format the cells as needed, but there's nothing you can do inside the CSV to affect what Excel is displaying.
I have tabulated data in an Excel spreadsheet (file size will likely never be larger than 1 mb). I want to use PHP to parse the data and insert in to a MySQL database.
Is there any advantage to keeping the file as an .xls/.xlsx and parsing it using a PHP Excel Parsing Library? If so, what are some good libraries to use?
Obviuously, I can save the .xls/.xlsx as a CSV and handle the file that way.
Thanks!
If you are just after the values, I would save it as a CSV. This is much easier to parse programatically, especially if you are trying to do this on a non-windows box.
That being said, there will be information lost in the export to CSV. It will only save the values of the cells - not their formatting information, formulas, etc. If you need to use that information, you're better off doing this straight from Excel.
Here is a PHP Excel Reading library. If you decide to read Excel files directly, this may help get you started.
If your excel files contain strictly data and contain no formulas, scripts, macros and etc., I would say parsing through Excel will only add development overhead, and will potentially slow down processing. It would probably be best to convert the files to CSV in this case.
Also consider that MySQL's 'LOAD DATA INFILE' command can be used to import entire CSV files into a table, this can potentially further uncomplicate matters for you.
when you provide a way for customers to upload excel/csv files, you should consider that
CSV files will only export one sheet
Having multiline cells will make the CSV parsing complicated
You cannot easily detect corrupted/incomplete CSV files
CSV files do not include formatting
Besides from that, importing CSV is a lot easier than importing XLS.
Remember that if you're importing the csv file directly into Mysql, that you may have problems with the date format (as Mysql uses a different date format to Excel). I find it easier to change the date fields in Excel first (to format yyyy-mm-dd) prior to saving as a csv file.
Edit: Although I've not used it myself, others have recommended Navicat as a very good tool for converting Excel spreadsheets or Access data into Mysql databases. May be worth a look.
With Office 2003 there's an XML format called SpreadsheetML which is a bit in-between XML and Excel. I've considered using this format to import/export data to a web site but the format turns out to be a bit complex. Internally, this format turns all references into relative references. (Relative from the current location.) Worse, some cells have an index, thus you might see a row with only two cells, but the second cell might be 6 columns away from the first cell. (In which case Index=5.) Basically, if you want to use the Excel format, you will need to have a good way to calculate the position of each cell and know how to translate the references in the cells in a proper way.
If you're onlyinterested in the data, CSV would be much, much easier to implement. As an in-between solution, you could define an XML schema and add an XML mapping to your spreadsheet to export the data to an XML file. It's more complex than CSV i9mport/export, but also a bit more robust. But the Excel or Excel XML formats themselves are horrible to implement. (Or just a nice challenge, if you're a real XML expert.)