java - 是否可以使用 Apache POI 设置 "spans"中一行的 "worksheet#.xml"属性

标签 java excel apache apache-poi xssf

这是我使用 MS Office Excel 创建的 .xlsx 文件内的“worksheet#.xml”。

<worksheet mc:Ignorable="x14ac" xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">
    ...
        <sheetViews>
            <sheetView tabSelected="1" workbookViewId="0">
                <selection activeCell="B27" sqref="B27"/>
            </sheetView>
        </sheetViews>
        <sheetFormatPr baseColWidth="10" defaultRowHeight="12.75" x14ac:dyDescent="0.2"/>
        <cols>
            <col min="1" max="1" customWidth="true" width="17.28515625" collapsed="false"/>
            <col min="2" max="2" customWidth="true" width="156.5703125" collapsed="false"/>
            <col min="3" max="3" customWidth="true" width="11.42578125" collapsed="false"/>
        </cols>
        <sheetData>
            <row r="1" spans="1:2" x14ac:dyDescent="0.2">
                <c r="A1" s="5" t="s">
                    <v>43</v>
                </c><c r="B1" s="1" t="s">
                    <v>44</v>
                </c>
            </row>
            <row r="2" spans="1:2" x14ac:dyDescent="0.2">
                <c r="A2" s="6" t="s">
                    <v>45</v>
                </c><c r="B2" s="2" t="s">
                    <v>46</v>
                </c>
            </row>
        </sheetData>
    ...
    </worksheet>

如果我使用 Apache POI 将行附加到此文件,我会得到没有任何跨度或格式的附加行

...
<row r="#">
   ...
</row>
...

有没有办法使用 Apache POI 设置行的跨度?

最佳答案

您可以通过以下方式创建合并单元格:

CellRangeAddress region = CellRangeAddress.valueOf("B2:E5");
sheet1.addMergedRegion( region );

关于java - 是否可以使用 Apache POI 设置 "spans"中一行的 "worksheet#.xml"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25182090/

相关文章:

java - java中的默认类加载器是将所有内容都保存在内存中还是留在文件系统中?

java - Spring AOP 表达式中的多个返回类型

java - HttpMessageNotWritableException : Could not write JSON: Could not initialize proxy AFTER adding data into DB

python - 使用 Python 将公式写入 Excel

string - 在 Perl 中解析 A​​pache 日志

java - 需要用于不同类的两个版本的 jar 文件

Excel VBA保护工作表而不锁定所有单元格

vba - 对象 'Value' 的方法 'Range' 失败

php - Service unavailable 服务暂时不可用错误

java - 如何解决 INKApi 错误