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 :/
Related
I have an ETL process set up to take data from an Excel spreadsheet and store it in a database using SSIS. However, one of the columns in the the Excel file is formatted as a percent, and it will sometimes erroneously be stored as a NULL value in the database, as if there was some sort of translation error.
Pictured is the exact format being used for the column in Excel.
Interestingly, these percent values do load properly on some days, but for some reason one particular Excel sheet I was given as an example of this issue will not load any of them at all when put through the SSIS processor.
In Excel, these values will show up like "50.00%", and when the SSIS processor is able to translate them properly it will display as the decimal equivalent in the database, "0.5", which is what I want instead of the NULL values. The data type I am using in SSIS for this is Unicode string [DT_WSTR], and it is saved as an NVARCHAR in the database.
Any insight as to why these values will sometimes not display/translate as intended? I have tried messing around with the data types in SSIS/SQL Server, but it has either resulted in no change or error. When I put test values in the Excel sheet, such as "test" to see if it is importing anything at all from this column, it does seem to work (just not for the percent numbers that I need).
The issue was caused by the "mixed data types" that were present in the first few rows of my data (the "mixed" part being blank fields), which would explain why some sheets would work and others wouldn't.
https://stackoverflow.com/a/542573/11815822
Setting the connection string to accommodate for this fixed the issue.
I loaded an Excel file into an SQL table. The Excel file, one field consists of VARCHAR data (of data type general). When loaded into an SQL table, some of these values are prefixed with zero.
Example: in the Excel file it is 1081999 the same value become 01081999 in the SQL table.
What might be the reason for this ?
Excel will hide leading 0's as it identifies the fields content as a number and displays it as such. I would assume that the excel worksheet does indeed contain these leading 0's and they are simply not shown by Excel. If you change the type of the column from General to Text do they show up??
As a side note, if these are indeed numbers you should be storing them in a numeric datatype in the database...
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.
So the following code, reads in a tab delimited file in my datagridview, however the formatting is all over the place. One field in particular, is a sequence number, padded with zeros. After the import, all leading zeros go away leaving me with 1,2,3,etc. There is also a date field, after import it tacks on the time.
In theory, I need to treat every field as text on import. However, the number of fields on import could change. So one file might have 10 fields, the next file might have 200 fields.
Here's my connection string:
Dim ConStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Temp';Extended Properties='text';"
My schema includes the following:
Format=TabDelimited
TextDelimiter="
I've read where you can identify each field with a specific format. Very tedious to do this, especially if the fields can grow and shrink in size.
Suggestions?
When I export report from cognos to excel 2002 or 2007 format I want to convert the numbers to numeric data type.
I face issues after exporting when i try to find sum of certain columns it has values as
23,3456|
2356|
45,686.89|
20.00
due to this comma or other characters its taking the columns as text or some other data type.
so I manually convert to numeric data type and then apply summation functions. Need a solution to avoid this.
I want the decimal values to be decimal and numeric values to be numeric.
The region/language settings of your Cognos install does not match the region/language settings of Excel (which is inherited from Windows). The best solution is to adjust Windows settings to match Cognos or vice-versa.
Alternatively in the report in question you can override the Data Format of the values by selecting them and choosing Data Format from the properties window. From there you can adjust various settings such as forcing a specific data type as well as other options such as whether to use a comma separator.