简体   繁体   English

将背景色添加到DocX4J生成的Excel行中

[英]Add background color to Excel rows generated by DocX4J

I'm using DocX4J for creating an excel file. 我正在使用DocX4J创建Excel文件。 Now I want to give some rows a background color, depending on a calculation done before creating the excel. 现在,我想为某些行提供背景颜色,具体取决于创建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. Java-Doc也不是很有帮助。 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 ... 确实很难找到一些文档...

I think you need to add a row element to worksheet/sheetData, for example: 我认为您需要在worksheet / sheetData中添加一个row元素,例如:

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

and corresponding entries in the styles part. 以及样式部分中的相应条目。 Look at fills, cellStyleXfs, cellXfs. 查看填充,cellStyleXfs,cellXfs。

You can research these by looking them up in the spec, at http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/index.html 您可以通过在规范中查找它们来进行研究, 网址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. 准备编写代码时,可以上载包含所需内容的xlsx ,然后单击以为您生成代码。

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. 简而言之,最好的方法是,一旦对Open XML部件和docx4j基于JAXB的方法有了基本的了解,便是使用代码生成器,规范以及docx4j的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM