Ignore:
Timestamp:
Mar 19, 2019, 11:09:07 AM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #2161: Import data from Excel files

Moved auto-detection of Excel files into the FlatFileParser and added some methods for date/timestamp formatting with sensible defaults. This should make it possible for more or less all plug-ins or code that uses the FlatFileParser to import from Excel files (via auto-conversion to CSV) as long as the data is in the first sheet. To get access to other sheets the 'charset' must specify the sheet name or index instead.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/common/plugin/parse_file.jsp

    r7654 r7655  
    169169      fileInputStream = wex.wrapInputStream(fileInputStream);
    170170    }
    171    
    172     if (excelMode)
    173     {
    174       // TODO - this should be inside the FlatFileParser
    175       String dateFormat = Values.getString(request.getParameter("dateFormat"), "yyyy-MM-dd");
    176       XlsxToCsvUtil util = new XlsxToCsvUtil();
    177       util.setDateFormat(new DateFormatter(dateFormat));
    178       util.setEvaluateFormulas(true);
    179       util.readWorkbook(fileInputStream);
    180       SheetInfo sheetInfo = util.getSheetAsCsv(sheet);
    181       fileInputStream = sheetInfo.parseToCsv();
    182     }
    183    
    184     parser.setInputStream(fileInputStream, charsetName);
     171
     172    String dateFormat = Values.getStringOrNull(request.getParameter("dateFormat"));
     173    if (dateFormat != null) parser.setDefaultDateFormat(new DateFormatter(dateFormat));
     174    String timestampFormat = Values.getStringOrNull(request.getParameter("timestampFormat"));
     175    if (timestampFormat != null) parser.setDefaultTimestampFormat(new DateFormatter(timestampFormat));
     176    String decimalSeparator = Values.getStringOrNull(request.getParameter("decimalSeparator"));
     177    if (decimalSeparator != null)
     178    {
     179      char ds = "dot".equals(decimalSeparator) ? '.' : ',';
     180      parser.setDefaultNumberFormat(NumberFormatUtil.getNumberFormat(ds, (char)0));
     181    }
     182   
     183    parser.setInputStream(fileInputStream, excelMode ? sheet : charsetName);
    185184    lastLine = parser.parseHeaders();
    186185    dataIsFound = lastLine == FlatFileParser.LineType.DATA || lastLine == FlatFileParser.LineType.DATA_HEADER;
Note: See TracChangeset for help on using the changeset viewer.