1

I'm creating an ODS spreadsheet using SODS (https://github.com/miachm/SODS). This is a single-sheet, non formatted file. LibreOffice is happy with it, as is Google Spreadsheets. Excel, on the other hand, claims it contains errors, and when it attempts to fix it, it damages the data.

How can I make Excel happy about this file*?

Code (This is a Play/Scala program, accidentsDatasetCols are column extractors that generate cell content):

val sheet = new Sheet("accidents")
    // add title row
    sheet.appendColumns(accidentsDatasetCols.size)
    sheet.appendRow()
    val titleRow = sheet.getRange(0,0,1,accidentsDatasetCols.size)
    accidentsDatasetCols.zipWithIndex.foreach( c => {
      titleRow.getCell(0,c._2).setValue(c._1.name)
    } )

    // add data rows
    for {
      workAccidents <- accidents.listAllAccidents()
    } yield {
      for ( acc <- workAccidents ) {
        sheet.appendRow()
        val row = sheet.getRange(sheet.getLastRow,0, 1, accidentsDatasetCols.size)
        accidentsDatasetCols.zipWithIndex.foreach( c => row.getCell(0,c._2).setValue(c._1(acc)) )
      }
      val sprd = new SpreadSheet()
      sprd.addSheet(sheet, 0)
      var bytes:Array[Byte]=null
      Using( new ByteArrayOutputStream() ){ bas =>
        sprd.save(bas)
        bas.flush()
        bytes = bas.toByteArray
      }
      Ok(bytes).as("application/vnd.oasis.opendocument.spreadsheet")
        .withHeaders("Content-Disposition"->"attachment; filename=\"work-accidents.ods\"")
    }

Thanks!

  • Alternatively, how can I make MS fix Excel already?!
Michael Bar-Sinai
  • 2,729
  • 20
  • 27
  • Just to narrow the scope of the error search: if a file that LibreOffice is happy with it is opened in Calc and re-saved with a different name (without changing the format, still as ODS), is Excel also engaged in sabotage with this re-saved file? – JohnSUN Mar 30 '21 at 12:14
  • Interesting.... If I open and save the file in LibreOffice, Excel is happy with it. – Michael Bar-Sinai Mar 30 '21 at 12:23
  • Perfectly! No, that is bad, of course. But now it is clear that it is too early to write to the MS, this is a SODS mistake, you need to write [**there**](https://github.com/miachm/SODS/issues) – JohnSUN Mar 30 '21 at 12:27
  • Agreed that this might be something in SODS, but LibreOffice AND Google Spreadsheets are happy. So Excel could improve here as well :-)) – Michael Bar-Sinai Mar 30 '21 at 13:35

1 Answers1

1

Author of the libray here!

At first glance, it seems Excel is expecting than the file defines default-style fields (default font family, default paragraph margin, etc...). This is not required by the standard and that's why it works perfectly in LibreOffice and Google Sheets.

This is quite odd but I am not suprised. It's not the first time Excel is causing problems by an awful implementation. For example, Excel declares tables of 1048573x16384 cells even though it's only using a few ones at the top. This is plain stupid and it doesn't make any sense: https://github.com/miachm/SODS/issues/12

Anyway, we can not change how Excel works. So I'll try to work around this new issue. It should be solved in the next version!

EDIT: The bug is solved now!

amchacon
  • 1,891
  • 1
  • 18
  • 29