title: xlsx to csv converter Java with apache poi
body: <p>My question is based on this <a href="https://stackoverflow.com/questions/17345696/convert-xlsx-to-csv-with-apache-poi-api">Question</a>. This is my build so far:</p>
  <pre><code>package converters;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.util.Iterator;
  
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  class XlsxtoCSV {
  
      public static void main(String[] args) {
  
          File inputFile = new File(
                  &quot;C:\\Users\\USR\\Desktop\\testExport.xlsx&quot;);
          File outputFile = new File(&quot;C:\\Users\\USR\\Desktop\\output.csv&quot;);
          xlsx(inputFile, outputFile);
      }
  
      static void xlsx(File inputFile, File outputFile) {
          String seperator = &quot;;&quot;;
          // For storing data into CSV files
          StringBuffer data = new StringBuffer();
          try {
              FileOutputStream fos = new FileOutputStream(outputFile);
  
              // Get the workbook object for XLSX file
              XSSFWorkbook wBook = new XSSFWorkbook(
                      new FileInputStream(inputFile));
  
              // Get first sheet from the workbook
              XSSFSheet sheet = wBook.getSheetAt(0);
              Row row;
              Cell cell;
  
              // Iterate through each rows from first sheet
              Iterator&lt;Row&gt; rowIterator = sheet.iterator();
              int i = 0; //I need 11 columns which can be empty
              while (i &lt; 11) {
                  row = rowIterator.next();
  
                  // For each row, iterate through each columns
                  Iterator&lt;Cell&gt; cellIterator = row.cellIterator();
                  while (cellIterator.hasNext()) {
  
                      cell = cellIterator.next();
                      
                      
                      switch (cell.getCellType()) {
                      case Cell.CELL_TYPE_BOOLEAN:
                          data.append(cell.getBooleanCellValue() + seperator);
  
                          break;
                      case Cell.CELL_TYPE_NUMERIC:
                          data.append(cell.getNumericCellValue() + seperator);
  
                          break;
                      case Cell.CELL_TYPE_STRING:
                          data.append(cell.getStringCellValue() + seperator);
                          
                          break;
  
                      case Cell.CELL_TYPE_BLANK:
                          data.append(&quot;&quot; + seperator);
                          break;
                      default:
                          data.append(cell + seperator);
  
                      }
                  }
                  data.append(&quot;\r\n&quot;);
                  i++;
              }
  
              fos.write(data.toString().getBytes());
              fos.close();
              System.out.println(data.toString());
          } catch (Exception ioe) {
              ioe.printStackTrace();
          }
      }
  }
  </code></pre>
  <p>but my problem is that it won't work properly if there is an line break in a cell, which is important for me.</p>
  <p>I need it to be exactly like when you &quot;save as csv&quot; in Excel.</p>