I have a configuration .txt file that I'm trying to upload into a new tab in an existing Google spreadsheet. I choose File>Import and select Insert new sheet(s)
, Detect automatically
(there is no delimiter and I want each line in the text file to be its own cell), and No
for auto-conversion of text.
The file uploads for the most part as I want, and it assigns each line of the config file to its own cell in the A column (about 1300 rows). However, some lines in the text file are indented with spaces to make it easier to read and categorize items. When I open the file in notepad I see these leading spaces on some lines, but when the file is uploaded to Google sheets the spaces are lost.
The original file looks something like this:
...
# comment about this next part
header:
var1: 2
subHeader:
var3: 'a'
var4: 'b'
var5: 'false'
# another comment
var6: 'lorem'
...
But when I import it into sheets I get this: (imagine each line is a separate cell in the A column)
...
# comment about this next part
header:
var1: 2
subHeader:
var3: 'a'
var4: 'b'
var5: 'false'
# another comment
var6: 'lorem'
...
Since there's no leading spaces, I can't tell which variables go under which headers/subheaders.
I have tried adjusting the delimiter in the import settings to each of the available options (auto, comma, tab, and custom), along with specifying a null custom value and a copy/pasted linebreak (not sure if that worked). All of these produced the same result, except for comma, which gave worse results that broke apart some plain text in comments.
I also tried copy and pasting straight from notepad and got the same result with leading spaces removed.
If I try manually typing data from the .txt file into Google Sheets without copy/paste, the leading spaces are preserved. It also works to copy one line at a time into a new cell, but this would be excruciatingly slow.
The only viable solution I can think of is to write a separate program that parses each line of the text file and inserts a leading period before each line, and then use spreadsheet formulas to drop the period. But this is not particularly elegant and I would prefer to do it all within Sheets (and in such a manner that I can reupload the file occasionally with updates).