473,441 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

txt2xls

In would like to convert very simple text files into .xls
files and I need some help.

Here is the format of a typical file:

# begin table.txt

This should go in the first row,
first column.

This should go in the first row,
second column.

====

This should go in the second row,
first column.

This should go in the second row,
second column.

====

This should go in the third row,
first column.

This should go in the third row,
second column.

# end table.txt

"====" separates different rows, whereas different colums are separated
by an empty line. table.txt should be converted into a table.xls
file containing a 3x2 table like this:

================================ ================================
This should go in the first row, This should go in the first row,
first column. second column.
-------------------------------- --------------------------------
This should go in the second row, This should go in the second row,
first column. second column.
-------------------------------- --------------------------------
This should go in the third row, This should go in the third row,
first column. second column.
================================ ================================

I use OpenOffice on Linux, but I have no experience at all about the .xls
format, so I would welcome help/pointers and especially snippets of code ;)
TIA,

Michele Simionato
Jul 18 '05 #1
2 3775
Perhaps this could help you:
http://sourceforge.net/projects/pyxlwriter/

Michele Simionato wrote:
In would like to convert very simple text files into .xls
files and I need some help.

Here is the format of a typical file:

# begin table.txt

This should go in the first row,
first column.

This should go in the first row,
second column.

====

This should go in the second row,
first column.

This should go in the second row,
second column.

====

This should go in the third row,
first column.

This should go in the third row,
second column.

# end table.txt

"====" separates different rows, whereas different colums are separated
by an empty line. table.txt should be converted into a table.xls
file containing a 3x2 table like this:

================================ ================================
This should go in the first row, This should go in the first row,
first column. second column.
-------------------------------- --------------------------------
This should go in the second row, This should go in the second row,
first column. second column.
-------------------------------- --------------------------------
This should go in the third row, This should go in the third row,
first column. second column.
================================ ================================

I use OpenOffice on Linux, but I have no experience at all about the .xls
format, so I would welcome help/pointers and especially snippets of code ;)
TIA,

Michele Simionato

Jul 18 '05 #2
Benjamin Niemann <b.*******@betternet.de> wrote in message news:<ch**********@online.de>...
Perhaps this could help you:
http://sourceforge.net/projects/pyxlwriter/


Thank you! The distribution contains an example that does exactly what I
want (with minor changes). I report here a snippet just for future
reference:

import pyXLWriter as xl

workbook = xl.Writer(xlsfilename)
worksheet = workbook.add_worksheet()
nrow = 0
for chunk in file(textfile).read().split("\n====\n"):
row = chunk.split('\n\n') # Split on empty line
for ncol, cell in enumerate(row):
worksheet.write([nrow, ncol], cell.strip())
nrow += 1

workbook.close() # needed
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: elbernice4us | last post by:
Hello, Iam joseph from india, i want some suggestion about, converting notepad to excel ( it can be done) but i have all the files in one field it has to be opened in 35 fieldd is it...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.