Link to home
Start Free TrialLog in
Avatar of cyber-33
cyber-33Flag for United States of America

asked on

Reading files from a folder into excel spreadsheet

I am looking for help; with an excel script that

1. reads all files from a given folder (path can be hardcoded)
2. opens them as text and copies the contents into excel spreadsheet with 2 columns:
a. FileName
b. FileContents

The resulting spreadsheet should have as many rows as there are files and should contain the contents of each file in the "FileContents" column.

Thank you, Experts!
Avatar of cyber-33
cyber-33
Flag of United States of America image

ASKER

Note, some files can be large and contain all sorts of weird characters. The trick is to insert the contents of each files into a single cell. I am attaching a few files as samples.
0004514.html
What is the format of the files you wish to import? Are they all of the same format? What is their extension?
Note that the maximum number of characters that Excel can write into a single cell is 32,767. There is no trick to writing that many and none to write more.
Files s are html.  But I want to treat them as text. I cam deal with yhe size limitations by importing a sybset of each file appearing within some html tags. For example, open a section of the file appearing between <claims> and </claims> tags. This part will be significantly smaller than the entire file.

Thank you for your help!
Also as the subsets are beeing imported, all the strange character can be replaced with spaces
Can we say that you want only the part of the file between <claims> tags?
And that you will be happy to truncate any part of that part that might exceed the maximum acceptable length?
Can we say that you want only those exceptional characters replaced which Excel might refuse to accept?
I would really appreciate a sample of such a file - duly sanitised for public view. Your links lead to all kinds of advertising. Perhaps you can upload them in txt format.
My commens are below:
Can we say that you want only the part of the file between <claims> tags?
[YES]

And that you will be happy to truncate any part of that part that might exceed the maximum acceptable length?
[YES]

Can we say that you want only those exceptional characters replaced which Excel might refuse to accept?
[YES]

I would really appreciate a sample of such a file - duly sanitised for public view. Your links lead to all kinds of advertising. Perhaps you can upload them in txt format.
[A duly sanitized file would be different from the sample I would like the import process to work with. The 2 files attached with everything in them represent a good sample of the data I will be working with]

Thank you for your help.
I haven't been able to get at your two files.
They are just text files in html format...
When I click on them they open a Web site. Perhaps they execute. If they are text files change their extension to txt.
Thank you.
I have now received your two files. Unfortunately, I will be travelling these next four days, leaving even my laptop behind, and expect to return to a back log of work. More likely than not it will be a week before I can get back to you.
Faustulus
There seems to be a little problem with the claims tags. Neither file has <claims>, </claims> tags. The nearest I can find is <!--      Claims  --> and >Claims:<.
It seems that quite substantial parts of the files are not between these tags. Do you wish to revise the instruction?
The instructions are still valid. I used "claims"as a sample tag. The idea is that I can use some delimiters within the text to select the subsets within the files. The tags that u identified are perfect for my needs.

Thank you for your help!
ASKER CERTIFIED SOLUTION
Avatar of Faustulus
Faustulus
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you! I will test this solution on Monday and assign points then. Looking forward to it!
Verified - the code is clean, easy to read, follow and modify. Thank you!
Elegant solution. Excellent coding style. Knowledgeable expert.