CSV file contains trailing pipe delimiters - excel

I have an excel file and I exported the file into a pipe delimited csv file. However, in each row of the csv file, there are trailing pipes.
Here's a typical row:
dsad|asd|safd|sadaf| |||||||||
ddss|sd|saadfdaf|dadf |||||||||
Does anyone know how not to include those trailing pipes while exporting to csv from excel?
Thanks.

The sheet you are exporting probably contains cell that excel believes has values in them (I call them ghost cells). To prevent this behaviour, I have two suggestions:
Copy the spreadsheet to a fresh new spreasheet and export again. It should be fine.
Delete all the columns after the last column containing data (Do not use the Delete/Del key, select the columns till the end and use Ctrl+- instead). After this, save the workbook then export again.
If those don't work, there's probably some rows with actual data somewhere, and there, the data will be correctly delimited by the pipes. Might be best to count the number of columns of data that you have and make sure your resulting csv file has the same number of columns.
If this still doesn't work... just shout I guess? ^^;

Related

How do I export an Excel data sheet to a .txt file as Delimiter colon?

I have a .txt file that was given to me (exported from a database) that includes columns and rows. I was told some of data was in the wrong column. I just needed to move it to the next column over. I opened the .txt file in Excel using the Data "From Text/CSV" option and made my changes. Once I was finished, I saved my file as a .txt file like it was given to me, however it's not in the same format. My .txt export kept the column and rows whereas the original file given to me had the information had the values separated with "|" characters. Do you know how I can get the data in the "|" format so I can send it back to them? See my screenshots for reference.enter image description here
Once you have opened the file in Excel and made your changes, you can use the steps in below link here to change the delimiter to "|" or anything else you would like...

How to Append CSV file via VBA without reading empty formatted cells

I have a code that is able to Append a range of data in a worksheet to an existing CSV file. However, I noticed that when the existing CSV file contains empty, but formatted cells beyond the end of the data range, the Append function takes into account those empty cells as well.
For example, the existing CSV file has 10 rows of data, while rows 11 to 20 are empty, but has been formatted (e.g. as "dd-mmm-yy"). So when I append the CSV file, the new data is added at row 21 instead of row 11.
Apart from manually deleting rows 11 to 20 in the CSV file, is there a quick fix to this? I have many existing CSV files, so it is not feasible to do the manual way. As to why some of the rows are empty, but formatted, it is due to some earlier amendments that took place.
Appreciate the help.
I have a code that is able to Append a range of data in a worksheet to an existing CSV file. However, I noticed that when the existing CSV file contains empty, but formatted cells beyond the end of the data range, the Append function takes into account those empty cells as well.
If you've written that code, it needs to account for the formatted cells you want to ignore. Let's say you're exchanging data from a .xlsx file to a .csv file and all of this is being done inside the Excel platform. Then for example, if "General" is the format that works best for you, but some trailing cells in .csv column A, Sheet 1 are not that, then have your code evaluate on a loop whether CSV Worksheets("Book1").Range("A[whatever row]").NumberFormat = "General"
Then have your code change the ones that aren't, to General; then proceed with the append.

SSIS Excel Destination exporting data with leading apostrophe

i cant believe i am struggling with this so much. you would think that since SSIS and Excel are both Mirosoft products they would interact seamlessly...
I have some data in a SQL Server table which i want to export to Excel. None of the data in any of the columns in SQL server have a leading apostrophe. So the solution is not use REPLACE.
Once I create an empty file through the Excel Destination task I open the file and format the columns to what I need them to be save and close the file. I run the package when i open the file all columns are preceded with a ' e.g. 'WA or '1234. If i recreate the file again following the procedure above and i format the columns and enter data into the first row, save the file and rerun the package, the data in the excel file is inserted correctly without any leading '.
How do i remove the leading apostrophe without having to insert a template row?
What is the best practice solution for this? The data is going to be uploaded into another database at another company and they dont want the leading apostrophe's.

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.

Number format in CSV file

I've got a macro that imports data from a SQL db to excel then saves the results as a CSV file. When it saves to CSV the formatting of two of the columns is lost, resulting in the numbers not displaying correctly.
Column 1 contains 12 digit numbers such as '800000000000' which are showing in the CSV file as '8E+11'
Column 2 contains 10 digit numbers such as '4880000000' which are showing in the CSV file as '4.88E+09'
The data displays fine when it is first imported to excel, the problem occurs when saving to CSV, although when I expand column 2 in the CSV file it displays the full number. This doesn't work for column 1 though, I have to change the formatting of the cell.
I usually run the macro then send the created CSV file on to a colleague, is there a way I can keep the number formatting without having to open and edit the CSV file?
Thanks
Adding "=" before the quotes preserves the pattern
For Example if your csv file is like
A1,col1,col2,col3,="001"
The 5th column will still be 001 when opened in excel

Resources