1

ここで、「setColumnSpannedNumber()」を使用してセルをマージ/スパンできますが、セルの背景色と配置を設定できませんでした。現在、odfdom-java-0.8.6.jar を使用しています。設定方法を教えてください。セルの色。ありがとうございました。

 try 
    {
            document = OdfSpreadsheetDocument.newSpreadsheetDocument();
            OdfOfficeSpreadsheet contentRoot = document.getContentRoot();
            Node node = contentRoot.getFirstChild();
                while (node != null) {
                    contentRoot.removeChild(node);
                    node = contentRoot.getFirstChild();
                }
            } catch (Exception e) {
               signature throws Exception
                throw new ReportFileGenerationException("Cannot create new ODF spread sheet document. Error: "+ e.getMessage(), e);
            }
            OdfTable table = OdfTable.newTable(document);

    for (int i = 0; i < report.size(); i++) {
        List<String> row = report.get(i);

        for (int j = 0; j < row.size(); j++) {          
            String str= row.get(j);                
    String newStr = str.replaceAll("[\u0000-\u001f]", "");              
        OdfTableCell cell = table.getCellByPosition(j, i);

            if(i==0 && j==17)
            {        
               cell.setColumnSpannedNumber(4);
                cell.setCellBackgroundColor(new Color("#ffff00"));
               cell.setHorizontalAlignment("center");                   
            }

            else if(i==0 && j==21)
            {
                cell.setColumnSpannedNumber(4);                 
           }
            else if(i==0 && j==25)
            {
                cell.setColumnSpannedNumber(4);
            }
            else if(i==0 && j==29)
            {
                cell.setColumnSpannedNumber(4);
            }
            else if(i==0 && j==33)
            {
                cell.setColumnSpannedNumber(4);
            }
   cell.setStringValue(newStr);

     }
    }

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        document.save(os);
        return os.toByteArray();
    } catch (Exception e) {     
        throw new ReportFileGenerationException("Cannot save the ODF spread sheet document as byte array. Error: "
                + e.getMessage(), e);
    } finally {
        Helper.close(os);
    }
}

}
4

1 に答える 1