I have a file produced by a proprietary third party application that is effectively a CSV with one specific exception: the first 3 rows do not follow a tradtional CSV format.
I can open the file in Excel, and the file represents itself correctly. If I open, hit save (changing nothing) and then attempt a reimport, the reimport fails. If I open the file with Notepad, hit save, and reimport, the file import succeeds. I used a hex editor (HxD) to review the original file and compare it against the file that gets saved after opening in Excel and discovered the issue.
As I have identified the issue, I'll save space by providing an example that only includes the header (s) and the first data entry line. To prevent confusion, I have limited the cell contents in the example. It isn't the contents of the cells that are the problem, it's how Excel ultimately saves it (correctly, but my third part application rejects it).
Original Exported Cells
A1 'title 1
A2 'title 2
A3 'title 3
A4 B4 C4 D4 E4 F4 G4 H4 I4 'table header
A5 B5 C5 D5 E5 F5 G5 H5 I5 'first line of data
Note: only cells A1, A2 and A3 in the original file contain data, the remaining cells in that row are empty. The original file opened in HxD shows this:
A1 (CR) (LF)
A2 (CR) (LF)
A3 (CR) (LF)
A4 (TAB) B4 (TAB) C4 (TAB) D4 (TAB) E4 (TAB) F4 (TAB) G4 (TAB) H4 (TAB) I4 (CR) (LF)
A5 (TAB) B5 (TAB) C5 (TAB) D5 (TAB) E5 (TAB) F5 (TAB) G5 (TAB) H5 (TAB) I5 (CR) (LF)
Where (CR) is HEX: 0D
(LF) is HEX: 0A
(TAB) is HEX: 09
The issue is that when Excel saves the original file after opening, it saves the file with additional (TAB) (as might be expected given how CSV traditionally work). It becomes:
A1 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A2 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A3 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A4 (TAB) B4 (TAB) C4 (TAB) D4 (TAB) E4 (TAB) F4 (TAB) G4 (TAB) H4 (TAB) I4 (CR) (LF)
A5 (TAB) B5 (TAB) C5 (TAB) D5 (TAB) E5 (TAB) F5 (TAB) G5 (TAB) H5 (TAB) I5 (CR) (LF)
Using HxD, if I remove all the (TAB) characters from the A1, A2 and A3 rows and save, the third party application accept the file. This has been a project I have been working on for just under a week. I have overcome every other hurdle but this doesn't exist within Excel per se. I need the solution to exist with something I can run from Excel (i.e. VBA). Third party helper apps are OK.
Basically I need a VBA script to replace the raw HEX:
09 09 09 09 09 09 09 09 0D 0A
with
0D 0A
Does anyone have a resource to help me out here?
P.S. I did locate this post:
I can open the file in Excel, and the file represents itself correctly. If I open, hit save (changing nothing) and then attempt a reimport, the reimport fails. If I open the file with Notepad, hit save, and reimport, the file import succeeds. I used a hex editor (HxD) to review the original file and compare it against the file that gets saved after opening in Excel and discovered the issue.
As I have identified the issue, I'll save space by providing an example that only includes the header (s) and the first data entry line. To prevent confusion, I have limited the cell contents in the example. It isn't the contents of the cells that are the problem, it's how Excel ultimately saves it (correctly, but my third part application rejects it).
Original Exported Cells
A1 'title 1
A2 'title 2
A3 'title 3
A4 B4 C4 D4 E4 F4 G4 H4 I4 'table header
A5 B5 C5 D5 E5 F5 G5 H5 I5 'first line of data
Note: only cells A1, A2 and A3 in the original file contain data, the remaining cells in that row are empty. The original file opened in HxD shows this:
A1 (CR) (LF)
A2 (CR) (LF)
A3 (CR) (LF)
A4 (TAB) B4 (TAB) C4 (TAB) D4 (TAB) E4 (TAB) F4 (TAB) G4 (TAB) H4 (TAB) I4 (CR) (LF)
A5 (TAB) B5 (TAB) C5 (TAB) D5 (TAB) E5 (TAB) F5 (TAB) G5 (TAB) H5 (TAB) I5 (CR) (LF)
Where (CR) is HEX: 0D
(LF) is HEX: 0A
(TAB) is HEX: 09
The issue is that when Excel saves the original file after opening, it saves the file with additional (TAB) (as might be expected given how CSV traditionally work). It becomes:
A1 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A2 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A3 (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (TAB) (CR) (LF)
A4 (TAB) B4 (TAB) C4 (TAB) D4 (TAB) E4 (TAB) F4 (TAB) G4 (TAB) H4 (TAB) I4 (CR) (LF)
A5 (TAB) B5 (TAB) C5 (TAB) D5 (TAB) E5 (TAB) F5 (TAB) G5 (TAB) H5 (TAB) I5 (CR) (LF)
Using HxD, if I remove all the (TAB) characters from the A1, A2 and A3 rows and save, the third party application accept the file. This has been a project I have been working on for just under a week. I have overcome every other hurdle but this doesn't exist within Excel per se. I need the solution to exist with something I can run from Excel (i.e. VBA). Third party helper apps are OK.
Basically I need a VBA script to replace the raw HEX:
09 09 09 09 09 09 09 09 0D 0A
with
0D 0A
Does anyone have a resource to help me out here?
P.S. I did locate this post:
Write hex values to binary file in VBA Excel
Hello to all, I want to write the hexadecimal values to a binary file in order they look the same when I open in hex editor. My current code is this: Sub Write2Binary() Dim i As Integer Dim nFileNum As Integer Dim sFilename As String sFilename = "D:\OutputPath\Test.bin" strBytes = "F3...
www.mrexcel.com