Comments (6)
I want to use this feature, as soon as possible because of my diploma thesis. I am willing to try to add it by myself. Would you like to give me any guidelines?
For the moment, I have these categories and values :
categories = '=' + sheet + '!$A$8,' + sheet + '!$A$21,' + sheet + '!$A$34,' + sheet + '!$A$47,' + sheet + '!$A$60'
values = '=' + sheet + '!$E$11,' + sheet + '!$E$24,' + sheet + '!$E$37,' + sheet + '!$E$50,' + sheet + '!$E$63'
and I get this error,
File "cpusToReducers.py", line 608, in
main()
File "cpusToReducers.py", line 143, in main
excel.close()
File "/usr/local/lib/python3.3/dist-packages/xlsxwriter/workbook.py", line 235, in close
self._store_workbook()
File "/usr/local/lib/python3.3/dist-packages/xlsxwriter/workbook.py", line 394, in _store_workbook
self._add_chart_data()
File "/usr/local/lib/python3.3/dist-packages/xlsxwriter/workbook.py", line 1035, in _add_chart_data
(sheetname, cells) = self._get_chart_range(c_range)
File "/usr/local/lib/python3.3/dist-packages/xlsxwriter/workbook.py", line 1072, in _get_chart_range
sheetname, cells = c_range.split('!')
ValueError: too many values to unpack (expected 2)
where, everything irrelevant to xlsxwriter concerns to my code. The problem seems to be the extra '!' which are needed to separate every sheet name from the corresponding cell. When I exclude the extra '!' everything works predictably.
WORKAROUND
A possible, starting workaround following Excel notation for not
contiguous ranges, i.e.
not_contiguous_ranges = '= Sheet1!Range1, Sheet2!Range2, ...., SheetN!RangeN
it would be, inside _get_chart_range(self, c_range)
- split on ',' and take comma parts
- for each comma part, split on '!' and this way build a list of ( sheet_name, cells)
- for each element of ( sheet_name, cells) do the conversion for example from
Sheet1!$B$1:$B$5 to ( 'Sheet1', 0, 1, 4, 1 ). - return a list of tuples ( sheet_name, start_row, start_col, end_row, end_col)
from xlsxwriter.
The main issue here is that XlsxWriter needs to parse and read the data from the chart ranges so that it can be added to the chart as cached data.
This isn't strictly required by Excel, it generally recalculates the data when the file is opened. However, it can affect the display of the chart in other third party applications and when the chart is embedded in other applications such as Powerpoint.
However, if you don't need that then you can supply your own (potentially empty) data to the chart using the undocumented categories_data
and values_data
series options and then XlsxWriter will accept any formula string, including one for non-contiguous ranges.
For example:
import xlsxwriter
workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
# Create a new Chart object.
chart = workbook.add_chart({'type': 'column'})
# Write some data to add to plot on the chart.
data = [[1, 2, 3, 4, 5],
[22, 22, 99, 22, 22]]
worksheet.write_column('A1', data[0])
worksheet.write_column('B1', data[1])
# Configure the chart.
chart.add_series({'categories': '=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)',
'values': '=(Sheet1!$B$1:$B$2,Sheet1!$B$4:$B$5)',
'categories_data': [],
'values_data': [],
})
# Insert the chart into the worksheet.
worksheet.insert_chart('D3', chart)
workbook.close()
Note that the data (3, 99) isn't shown:
You just need to ensure that the formulas matches what Excel requires, including the parentheses.
'=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)'
from xlsxwriter.
Your solution works perfectly. Thanks a lot, not only for the great answer( accurate + example), but also for the instant reply. Generally, I am very satisfied from xlsxwriter. It's the best in its category, excellent documentation full of examples, easy to use, write the minimum, needed amount of code, full of useful features.
Finally, I would suggest undocumented but existent features to be documented in a separate chapter. This chapter could have a title such as "Experimental features" or "Alpha features" to clarify the "nature" of these features and warn somehow the programmer for any "risks" of these features. This way, a greater amount of features would be available for the benefit of all.
from xlsxwriter.
I've added support for non-contiguous chart ranges without having to use the _data
workaround.
It is on the master branch now and will be in the next PyPI release.
from xlsxwriter.
Is there something similar to this but for data_validation? So for example I drop duplicates on my Pandas DataFrame, but then want to use the left of values as the source
values, however I cannot use it as it exceeds 255 characters. My initial attempt was to just get the index of the series and add two to the values, however I am not sure how this would be written in source
from xlsxwriter.
@mayurpande please don't ask unrelated questions on closed issues like this. It spams everyone on the thread. Anyway, answered on StackOverflow: https://stackoverflow.com/a/66047007/10238
from xlsxwriter.
Related Issues (20)
- High memory usage by workbook when row to be written increases HOT 9
- EOL (End of Life) for PDF version of the documentation HOT 1
- Bug: When generating a xlsx, invalid file created with unrecoverable errors HOT 10
- How do I preserve formatting when writing a dataframme to an XLS file HOT 3
- How is append mode supposed to work when the target doesn't exist? HOT 4
- Bug: Ignoring multiple, different errors over same column range HOT 6
- worksheet.autofit() not working HOT 1
- feature request: appending formats instead of overwriting them HOT 1
- Bug: cell horizontal alignment reset to left when rotation == 270 and indent != 0 HOT 3
- Bug: Issues while creating multiple formats in new file HOT 1
- Bug: URLs disappear after 65530 HOT 1
- Issue with charts that fail to open in Microsoft 365 Excel HOT 7
- How to save the chart object as a png file? HOT 2
- Problem with embedding images HOT 3
- Feature request: Support theme based colors HOT 3
- Support multiple ranges in ignore_errors HOT 4
- question: Proposal to Increase Fuzzing Test Coverage HOT 2
- Bug: The file is corrupt and therefore cannot be opened HOT 10
- question: release v3.2 on conda-forge? HOT 1
- Duplicate/Create/Setting-up a Custom Table Style HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xlsxwriter.