Is there a way to easily take 3 text files and turn it into a multi-tab excel sheet via script?
files are file1.txt, file 2.txt, file3.txt – i would like it to output to excelsheet1.xls with 3 tabs.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t mention the format of the text files so real example code is difficult, but you can use Spreadsheet::WriteExcel for this. Look at the add_worksheet() method for creating new tabs.
Given that you say that each line is a number followed by text I am presuming that this is two columns per row with a space delimiting the first and second columns and only digits in the first column. If this is not true the regex below would need to be adjusted. That said, here’s some sample code.
Input files are given on the command line and processed in order, turning each one in to a tab named after the file name. The output file name is given on the command line last, after one or more input file names.
EDIT: Now including the improvements FM mentioned in his comment and a trivial CLI for specifying the output file name.