Well, at least with reference to the xml based file format, calling the
setZeroHeight() method does indeed hide the row.
Can I ask you to compile and run this piece of code for me please?
import java.io.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
*
* @author Mark Beardsley
*/
public class HidingTest {
public HidingTest(String filename) {
File file = null;
FileOutputStream fos = null;
Workbook workbook = null;
Sheet sheet = null;
Row row = null;
Cell cell = null;
CellStyle cellStyle = null;
try {
//
// Does the uwser want to create a binary or OpenXML based
workbook?
//
if(filename.endsWith("xlsx")) {
workbook = new XSSFWorkbook();
}
else {
workbook = new HSSFWorkbook();
}
// Create the cell style for the hidden row. I am going to try
and
// hide row 5.
cellStyle = workbook.createCellStyle();
cellStyle.setHidden(true);
// Insert a new sheet into the workbook
sheet = workbook.createSheet("Hiding Test");
for(int i = 0; i < 10; i++) {
row = sheet.createRow(i);
cell = row.createCell(i);
cell.setCellValue(i);
if(i == 4) {
row.setZeroHeight(true);
}
}
// Save the file away to disc.
file = new File(filename);
fos = new FileOutputStream(file);
workbook.write(fos);
}
catch(IOException ioEx) {
HidingTest.printException(ioEx);
}
finally {
if(fos != null) {
try {
fos.close();
fos = null;
}
catch(IOException ioEx) {
HidingTest.printException(ioEx);
}
}
}
}
private static void printException(Throwable th) {
System.out.println("Thrown: " + th.getClass().getName());
System.out.println("Message: " + th.getMessage());
System.out.println("Stacktrace follows:.....");
th.printStackTrace(System.out);
}
}
If you run it twice, something like this;
new HidingTest("C:/temp/Hidden.xlsx");
new HidingTest("C:/temp/Hidden.xls");
Then it should produce workbooks both of which have row 5 hidden. I have
checked the xml produced by the new HidingTest("C:/temp/Hidden.xlsx") call
as that is a simple matter of unzipping the archive and using a text ediotr
to take a look, and I found this fragment in the sheet1.xml file;
<row r="5" hidden="true"><c r="E5" t="n"><v>4.0</v></c></row>
which does indeed suggest that the setZeroHeight() method hides the row.
Will you still check that for me please and make sure that users can
successfully unhide the rows (the acid test so to speak)?
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Trouble-with-hiding-rows-in-Excel-tp5590626p5595608.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]