Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to output your tab limited data into an excel file. Just tweaking the MIME type would not make Excel perceive your tab limited <strong><em>text</em></strong> file as an excel document.</p> <p>Any spreadsheet file has a different binary structure altogether. It needs to have a <code>Workbook</code>, <code>Worksheets</code> and <code>Rows</code> of <code>Cell</code> data within; and they are clearly missing from your text file. That's why it doesn't work the way you expect it to.</p> <p>Here's how you could use <a href="http://poi.apache.org/" rel="noreferrer">Apache POI</a> to create a temporary excel file to be later used as a mail attachment.</p> <pre><code>Workbook xlsFile = new HSSFWorkbook(); // create a workbook CreationHelper helper = xlsFile.getCreationHelper(); Sheet sheet1 = xlsFile.createSheet("Sheet #1"); // add a sheet to your workbook while(rs.next()) { Row row = sheet1.createRow((short)0); // create a new row in your sheet for(int i = 0; i &lt; 12; i++) { row.createCell(i).setCellValue( helper.createRichTextString(exceldata)); // add cells to the row } } // Write the output to a temporary excel file FileOutputStream fos = new FileOutputStream("temp.xls"); xlsFile.write(fos); fos.close(); // Switch to using a `FileDataSource` (instead of ByteArrayDataSource) DataSource fds = new FileDataSource("temp.xls"); </code></pre> <p><strong><em>If you don't want to create a temporary excel file to the dump the data</em></strong> here's how to achieve the same</p> <pre><code>ByteArrayOutputStream bos = new ByteArrayOutputStream(); xlsFile.write(bos); // write excel data to a byte array fos.close(); // Now use your ByteArrayDataSource as DataSource fds = new ByteArrayDataSource(bos.toByteArray(), "application/vnd.ms-excel"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload