Hiya Jerry,
Am .06.2015, 17:30 Uhr, schrieb jer99 <
jerro...@gmail.com>:
> I'm new to python. I've dealt with VBA in Access, programed in PL/SQL
> (Oracle) and a few others.
> I have an Excel 2010 workbook with one worksheet.
> There are 7 columns with the data starting at row 6.
> The last column of data is Row 12.
>
> I would like to automate a process where Python would
> 1) Look for the first empty row (in this case it would return 13)
> 2) Add the date/time to column 1
> 3) add a value to column 2
> 4) add a formula to column 3
> 5)continue to add values, formulas in the row
Can we assume you intend to save the file after making the changes? If
this is the case then openpyxl is probably the best library. You can
otherwise use a combination of xlrd and xlsxwriter.
> That said, I have two questions -
> Which library is the best for this type of work?
> How do I find the next available row?
In openpyxl ws.max_row should give you the highest non-empty row. However,
if you only want to know in order to add data then just .append()
import datetime
import openpyxl
wb = load_workbook("sample.xlsx")
ws = wb.active
ws.append([datetime.datetime.now(), "a value", "=some formula()"])
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel:
+49-211-600-3657
Mobile:
+49-178-782-6226