Pregunta

I'm using DocX4J for creating an excel file. Now I want to give some rows a background color, depending on a calculation done before creating the excel. However, I can not find a method or something to add a backround color for a row. The Java-Doc is also not very helpful. I thought about coloring each cell, but cells also don't have a proper method. (They don't have any proper-named methods at all ...).

Anybody knows a hint? It is really difficult to find some documentation ...

¿Fue útil?

Solución

I think you need to add a row element to worksheet/sheetData, for example:

    <row r="2" s="1" customFormat="1" />

and corresponding entries in the styles part. Look at fills, cellStyleXfs, cellXfs.

You can research these by looking them up in the spec, at http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/index.html

When you are ready to code, you can upload an xlsx which contains whatever it is you want, then click to have code generated for you.

In short, your best approach, once you have a basic understanding of Open XML parts and docx4j's JAXB based approach to them, is to use the code generator, and the spec, and beyond that, docx4j's source code.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top