Skip to content

Commit

Permalink
Merge pull request #102 from rzymek/issues/98
Browse files Browse the repository at this point in the history
api to hide grid lines
  • Loading branch information
Olivier Chédru authored Mar 25, 2020
2 parents c2a19cb + d2859de commit 046d5a1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public class Worksheet {
*/
private VisibilityState visibilityState;

/**
* Whether grid lines are displayed
*/
private boolean showGridLines = true;
/**
* The hashed password that protects this sheet.
*/
Expand Down Expand Up @@ -571,7 +575,11 @@ public void flush() throws IOException {
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
writer.append("<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">");
writer.append("<dimension ref=\"A1\"/>");
writer.append("<sheetViews><sheetView workbookViewId=\"0\"/></sheetViews><sheetFormatPr defaultRowHeight=\"15.0\"/>");
writer.append("<sheetViews><sheetView workbookViewId=\"0\"");
if(!showGridLines) {
writer.append(" showGridLines=\"false\"");
}
writer.append("/></sheetViews><sheetFormatPr defaultRowHeight=\"15.0\"/>");
int nbCols = rows.stream().filter(Objects::nonNull).map(r -> r.length).reduce(0, Math::max);
if (nbCols > 0) {
writeCols(writer, nbCols);
Expand Down Expand Up @@ -627,4 +635,11 @@ private static void writeRow(Writer w, int r, boolean isHidden, Cell... row) thr
public void comment(int r, int c, String comment) {
comments.set(r, c, comment);
}

/**
* Hide grid lines
*/
public void hideGridLines() {
this.showGridLines = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,31 @@ public void comments() throws IOException {
String.valueOf(cellComment.getString())
);
}

@Test
public void hideGridLines() throws IOException {
byte[] data = writeWorkbook(wb -> {
Worksheet ws = wb.newWorksheet("Worksheet 1");
ws.hideGridLines();
});

assertFalse(isWorkSheetDisplayingGridLines(data));
}

@Test
public void showGridLinesByDefault() throws IOException {
byte[] data = writeWorkbook(wb -> {
Worksheet ws = wb.newWorksheet("Worksheet 1");
});

assertTrue(isWorkSheetDisplayingGridLines(data));
}


private static boolean isWorkSheetDisplayingGridLines(byte[] data) throws IOException {
XSSFWorkbook xwb = new XSSFWorkbook(new ByteArrayInputStream(data));
XSSFSheet xws = xwb.getSheetAt(0);
return xws.isDisplayGridlines();
}

}

0 comments on commit 046d5a1

Please sign in to comment.