2002 JI Open Discussion Posted August 18, 2006 Share Posted August 18, 2006 By: Tom - tomage CSV file formatting question 2003-08-04 16:24 Hi, I am generating a CSV file. The file format I am working toward has some header information that should not be delimited as normal CSV. I tried setting the width of this header element to the total width of the column elements in the detail band of the report. I expected this would avoid the header having a bunch of delimeters following it. My report has 11 columns. The header prints as "my header,,,,,,,,,,". In reviewing the JRCsvExporter class, it looks like the exportPage method doesn't respect the grid's colSpan value. Is this a bug? Is there a way for me to tell the CSV exporter that this row has only 1 column? Thanks for any insight. Tom By: Teodor Danciu - teodord RE: CSV file formatting question 2003-08-04 23:24 Hi, This is how the supplied CSV exporter works, at least for the moment. You can create your own exporter or enhace the existing one, if you want it to bahave in a particular way. I hope this helps. Teodor By: Tom - tomage RE: CSV file formatting question 2003-08-05 11:02 Thanks for the response Teodor. It was easy to fix in your CSV exporter as you have already set up the colSpan value for each element in the grid. I just added a check to increment the counter moving across the columns by an elements colSpan. See the change below. private void exportPage(JRPrintPage page) throws JRException, IOException { this.layoutGrid(page); StringBuffer rowbuffer = null; JRPrintElement element = null; String text = null; boolean isFirstColumn = true; for(int y = 0; y < grid.length; y++) { rowbuffer = new StringBuffer(); if (isRowUsed[y]) { isFirstColumn = true; for(int x = 0; x < grid[y].length; x++) { if(grid[y][x].element != null) { element = grid[y][x].element; if (element instanceof JRPrintText) { text = ((JRPrintText)element).getText(); if (text == null) { text = ""; } if (!isFirstColumn) { rowbuffer.append(this.delimiter); } rowbuffer.append( prepareText(text) ); isFirstColumn = false; /* * Change to support column spanning in CSV exports. * * This allows for header or footer reportElements with a properly configured width * to avoid unnecessary delimiters "my header,,,,,,,,,," * */ int colSpan = grid[y][x].colSpan; if (colSpan > 1) { x = x + colSpan; } } } else { if (isColUsed[x]) { if (!isFirstColumn) { rowbuffer.append(this.delimiter); } isFirstColumn = false; } } } if (rowbuffer.length() > 0) { this.writer.write(rowbuffer.toString()); this.writer.write("n"); } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now