MCPcopy Create free account
hub / github.com/apache/poi / writeTo

Method writeTo

src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java:339–416  ·  view source on GitHub ↗

Write this table out as XML. @param out The stream to write to. @throws IOException if an error occurs while writing.

(OutputStream out)

Source from the content-addressed store, hash-verified

337 * @throws IOException if an error occurs while writing.
338 */
339 public void writeTo(OutputStream out) throws IOException {
340 XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
341
342 // Work on the current one
343 // Need to do this, as we don't handle
344 // all the possible entries yet
345 CTStylesheet styleSheet = doc.getStyleSheet();
346
347 // Formats
348 CTNumFmts formats = CTNumFmts.Factory.newInstance();
349 formats.setCount(numberFormats.size());
350 for (Entry<Integer, String> fmt : numberFormats.entrySet()) {
351 CTNumFmt ctFmt = formats.addNewNumFmt();
352 ctFmt.setNumFmtId(fmt.getKey());
353 ctFmt.setFormatCode(fmt.getValue());
354 }
355 styleSheet.setNumFmts(formats);
356
357 int idx;
358 // Fonts
359 CTFonts ctFonts = CTFonts.Factory.newInstance();
360 ctFonts.setCount(fonts.size());
361 CTFont[] ctfnt = new CTFont[fonts.size()];
362 idx = 0;
363 for(XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
364 ctFonts.setFontArray(ctfnt);
365 styleSheet.setFonts(ctFonts);
366
367 // Fills
368 CTFills ctFills = CTFills.Factory.newInstance();
369 ctFills.setCount(fills.size());
370 CTFill[] ctf = new CTFill[fills.size()];
371 idx = 0;
372 for(XSSFCellFill f : fills) ctf[idx++] = f.getCTFill();
373 ctFills.setFillArray(ctf);
374 styleSheet.setFills(ctFills);
375
376 // Borders
377 CTBorders ctBorders = CTBorders.Factory.newInstance();
378 ctBorders.setCount(borders.size());
379 CTBorder[] ctb = new CTBorder[borders.size()];
380 idx = 0;
381 for(XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder();
382 ctBorders.setBorderArray(ctb);
383 styleSheet.setBorders(ctBorders);
384
385 // Xfs
386 if(xfs.size() > 0) {
387 CTCellXfs ctXfs = CTCellXfs.Factory.newInstance();
388 ctXfs.setCount(xfs.size());
389 ctXfs.setXfArray(
390 xfs.toArray(new CTXf[xfs.size()])
391 );
392 styleSheet.setCellXfs(ctXfs);
393 }
394
395 // Style xfs
396 if(styleXfs.size() > 0) {

Callers 1

commitMethod · 0.95

Calls 11

getStyleSheetMethod · 0.80
setCountMethod · 0.80
getCTFontMethod · 0.80
sizeMethod · 0.65
getValueMethod · 0.65
entrySetMethod · 0.45
getKeyMethod · 0.45
getCTFillMethod · 0.45
getCTBorderMethod · 0.45
toArrayMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected