473,480 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 3779
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
1673
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...
0
7055
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
6920
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
7059
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
6758
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
4499
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3011
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
1311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.