Am .02.2016, 22:59 Uhr, schrieb <
rachel.l...@gmail.com>:
> Hi everyone,
Hiya,
> I'm trying to use openpyxl to do the following:
>
> 1. Open an Excel file with pre-entered formulas and paste values into it.
> 2. Save the file under a unique name.
> 3. Re-open the unique file as data_only=True so I can...
> 4. Get the values of the calculated cells, not just the formulas.
>
> Steps 1 and 2 work just fine. Step 3 also seems to work, but when I try
> to
> access calculated values from the file, their value appears to be
> None. Non-calculated values can be accessed without a problem.
As Thomas said, it's not entirely clear what's being saved by what in Step
2.
> Here's the relevant code for Steps 3 and 4.
Ugh!
> current_individual_file = openpyxl.load_workbook(individual_filename,
> data_only=True)
> current_sheet =
> current_individual_file.get_sheet_by_name(unicode('Template
> 2'))
Why unicode?
current_sheet = current_individual_file['Template 2']
> value_list = []
> for row in range(14, 26):
> value_list.append(current_sheet['AB' + str(row)].value)
In openpyxl you'll never need to manually create 'A1' style coordinates.
values = []
for row in current_sheet['AB14':'AB26']:
for cell in row:
values.append(cell.value)
(can be done in a single list comprehension if you'r feeling adventurous)
> Although the calculated cells show correct values when I open the Excel
> document, value_list comes out as a list of Nonetype objects. I have
> tried
> using internal_value as well.
>
> I have done quite a bit of searching for a solution but haven't found
> anything exactly analogous to my situation. Thanks in advance for your
> help.
Hope this helps you along. If you're still having problems you may need to
supply a file.
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