I'm using a PHPExcel Library to Export my database to excel...
I have a value 200010058502 to be exported but it will appear as 2.0001E+11 in the excel file
Any idea how to format this to make the value the same in my database
My PHPExcel code to fetch value from the database:
$objPHPExcel->getActiveSheet()->SetCellValue("J".$xlsRow,$row['acct_no']);
Thank You in advance
This most likely is an Excel display issue, not a PHP issue.
To verify that the number is imported correctly, highlight the cell and check the status bar. It should show the entire number, and not in scientific notation. If it doesn't, ignore the rest of my answer.
Increase the width of your Excel cell to be more than 11 digits wide. Excel will automatically convert numbers to scientific notation that are too large to physically fit in the display. If it still is in scientific notation, change the formatting of the cell (cell->format->number) to show a number with zero decimal places.
Related
I am currently working with a macro that gathers data (code identifier) from a source with a print screen and pastes it to excel.
Problem is, every time a data point (identifier) is a value with an "E" included, excel interprets as a scientific notation and changes the original value.
Is there a way to make excel set the column in which I have those values to text before pasting, or for it to paste the whole content as text automatically?
Thanks for the help.
I have a SQL Server view I'm pulling into an excel macro workbook. However, one of the date fields is being treated as a number by excel and it's leading 0 is subsequently being stripped off. Is there a datatype I can convert my date field to in SQL so that excel does not strip off it's leading zero when the view is imported into the workbook?
How are you pulling the data in? AFAIK there's no Excel-wide setting to keep the leading zeros, however there are ways to keep them, or to add them back:
From Microsoft
If you're using the import wizard,
Convert the number to text when you import text data
In Step 3 of the Text Import Wizard (On the Data tab, in the Get
External Data group, click From Text), you can select the column of
data that contains the credit card number, and then explicitly choose
a Text column data format.
Alternatively, if you already imported the data and there's a pattern/structure to it, you can create a custom format:
Use a custom format to keep the leading zeros
If you want to resolve the issue just within the workbook because it's
not used by other programs as a data source, you can use a custom or a
special format to keep the leading zeros. This works for number codes
that contain fewer than 16 digits,
In addition, you can separate some of the digits in your number codes
with dashes by adding these dashes to the custom format. For example,
to make a phone number more readable, you can add a dash between the
international code, the country/region code, the area code, the
prefix, and the last few numbers.
Edit: I'm not to keen on SQL, so can only offer more Excel focused ideas :/
I know many discussions have addressed this but I have not found a solution.
I regularly produce worksheets with about 100 records of text and date fields, each of which must be transposed into a 2-column table and printed to a PDF file.
To do this I have been using VBA code which works through the worksheet rows to sequentially: copy/transpose into two columns in a separate worksheet (Template) and then use rng.ExportAsFixedFormat Type:=xlTypePDF to create the PDF file.
It has all been working fine for several years, until someone recently noticed that sometimes the largest field does not show all the text from the Excel cell. It is invariably cut off after about 1000 - 1100 characters.
Many discussions mention that there is a 1024 limit on cell displays, but I thought this only applied to Excel 2003 and before - 2007 should be fine shouldn't it? In any case, I have found it is always possible to manually adjust the Excel field to reveal all of the text (both in the original worksheet and the temporary 2-column Excel table), sometimes totalling more than 2000 characters. Of course, I don't want to manually adjust and print to PDF 100 times on a regular basis. So I used AutoFit: Sheets("Template").Rows("1:18").Selection.EntireRow.AutoFit
Unfortunately this does not seem to duplicate the manual cell expanding that we have tried successfully. None of the cells is merged. All are wrapped and General formatted. I have tried cleaning text entries via Notepad before entry and inserting blank rows with Alt-F (as suggested elsewhere).
If AutoFit will not work, I am thinking maybe I could include some code to set a customised row height for each table by getting the total word count (is there a function?) and setting row height to about 0.8 * number of words - based on initial calculations.
Any ideas please?
I've used a method similar to what you suggested your last paragraph but with a character count instead of a word count. The VBA function is:
len(range("A1").value)
I did it since I had merged cells and they wouldn't autofit.
You'll have to calibrate for your column width, font and font size but from what I've learned there's no exact method. If you set your characters per line factor too high you might cut off a line, too low and you might get a blank line.
I am uploading a currency rate workbook through a filehandler in VB.net through System.Data.OleDb.OleDbConnection.
When viewing the rates in the Excel sheet, I see 0.55865921787709500000.
Viewing the same rate in the datatable under debug mode, I see 0.55865921787709480000.
Under Excel, the decimal places are set to 20 - seems to just pad out zeroes past decimal position 15.
I've tried reading/writing the cells to a text file (same '500000' result).
Tried saving the workbook as a comma-delimted text file - same '500000' result.
The rate worksheet is created from another web site. I have attempted to add a 16th digit to the worksheet, but it flips back to zero after I move off the cell. I know Excel has a 16-digit precision limit. In this case, it appears to be storing more.
Is there any way to peek at the actual stored value in the workbook - other than examining the datatable?
Excel is retaining more than 15 significant digits - depending on what system created the original Excel document. In this case, the doc was produced by Crystal Reports. The "extra" significant digits can be viewed using the OLEDB connection against the Excel spreadsheet or by viewing it through the Google Docs version of Excel.
In this particular case, I had to make the SQL-stored rates match the spreadsheet. I converted each rate to a decimal and a string. I used the string to locate the period in the rate and start counting consecutive zeroes that appear after the decimal. This count was added to 15 as the number of digits on a system round of the decimal. The rounded number matched the figures shown when viewing the information in Excel.
I have a field in my Excel as follows
€250
€240
Free
....
In my SQL2005 Preview this looks as follows
250
240
(Blank)
So it doesnt like Symbols and Text in this column altho it is going to a varchar column.
Any Ideas ?
Check whether the € is stored in your excel file as part of the value of a cell or as formatting.
I was trying to reproduce your problem, and when I entered €250 into a cell, when I later selected the cell to check the value, it was 250 (Excel had decided that I was trying to give the cell a numerical value, formatted as currency)
If that isn't the problem, trying using nchar as your column type rather than varchar. nchar allows a wider range of symbols.