Code Monkey home page Code Monkey logo

Comments (7)

sillydong avatar sillydong commented on August 29, 2024 1

Is there any plan to achieve this feature?

from unioffice.

tbaliance avatar tbaliance commented on August 29, 2024

@freb I'll have a look, allowing editing the spreadsheet shouldn't be too bad. If the charts work like they do in Excel, all you need to do is drop the numCache elements in your chart1.xml to cause the chart to be redrawn. I'll test and see if that works in Word as well. Since gooxml can evaluate formulas, it could always regenerate the numCache elements, but dropping them is easier and has worked so far.

from unioffice.

kkesley avatar kkesley commented on August 29, 2024

Hi! how do you add charts to word documents?

from unioffice.

tbaliance avatar tbaliance commented on August 29, 2024

@kendrickkesley Sorry, this still hasn't been done yet.

from unioffice.

freb avatar freb commented on August 29, 2024

Without unioffice support, it should be possible to get most of the way there. The approach would be to open up the docx file as a zip file and then find and edit the embedded spreadsheet using unioffice.

The only real question is whether we have access to all of the rels needed to follow the trail of IDs. Last time I was digging into the rels for something unrelated, I was unable to locate what I needed, but I think it ended up being accessible in doc.DocBase.Rels.

For reference, here are my notes on the involved files and structures:

word/document.xml:

<wp:inline distB="0" distL="0" distR="0" distT="0" xmlns="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:xml="http://www.w3.org/XML/1998/namespace">
	<wp:extent cx="5729161" cy="3787072"/>
	<wp:effectExtent b="4445" l="0" r="5080" t="0"/>
	<wp:docPr id="5" name="Chart 5"/>
	<wp:cNvGraphicFramePr/>
	<a:graphic>
		<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
			<c:chart r:id="rId9" xmlns="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:s="http://schemas.openxmlformats.org/officeDocument/2006/sharedTypes" xmlns:xml="http://www.w3.org/XML/1998/namespace"/>
		</a:graphicData>
	</a:graphic>
</wp:inline>
</w:drawing>

It has rId9. This is looked up in word/_rels/document.xml.rels:

<Relationship Id="rId9" Target="charts/chart1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart"/>

This references file charts/chart1.xml, which is located at word/charts/_rels/chart1.xml.rels (not sure if this is accessible from unioffice):

<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Target="../embeddings/Microsoft_Excel_Worksheet.xlsx"/></Relationships>

Which references ../embeddings/Microsoft_Excel_Worksheet.xlsx, which isn't a path from chart1.xml.rels, but maybe is from charts. It points to word/embeddings/Microsoft_Excel_Worksheet.xlsx, which is the embedded spreadsheet.

Altering the spreadsheet and then setting doc.Settings.SetUpdateFieldsOnOpen(true) would probably update the chart numbers, but I haven't confirmed. Deleting numCache would be better as Todd mentioned.

I also considered updating the numCache directly without altering the embedded spreadsheet. This works OK, but as soon as you update fields in the document, like a table of contents, the numbers will revert.

from unioffice.

gunnsth avatar gunnsth commented on August 29, 2024

@freb What would you envision the API for this to be like?

from unioffice.

freb avatar freb commented on August 29, 2024

@gunnsth Sorry for the slow response. The API will really depend on exactly how much functionality you want to support around this. For my use case of taking an existing docx file that already has a chart as a placeholder and updating its values, it could be as simple as providing access to the embedded xlsx chart file and providing a mechanism for dropping the numCache.

If, however, you want to support creating charts from scratch, this would obviously get a lot messier. When I was looking into this before, I didn't spend a lot of time reviewing the chart XML, but it looked involved enough that it wasn't something I wanted to tackle for my needs.

from unioffice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.