Page 1 of 1

Need help in adding a cell with "abc"

PostPosted: Sat Apr 21, 2012 3:00 am
by aherrera
Hi all,

I can create an Excel Workbook with no problems if I'm creating a cell with "1234" in it.
I used the CreateSimpleSpreadsheet.java example from the following URL:
http://www.docx4java.org/trac/docx4j/browser/trunk/docx4j/src/xlsx4j/java/org/xlsx4j/samples

Code: Select all
   private static void addContent(WorksheetPart sheet) throws Exception {
      // minimal content already present
      SheetData sheetData = sheet.getJaxbElement().getSheetData();
      
      // add stuff
      Row row = Context.getsmlObjectFactory().createRow();
      Cell cell = Context.getsmlObjectFactory().createCell();
      cell.setV("1234");
      Cell cell2 = Context.getsmlObjectFactory().createCell();
      cell2.setV("ABC"); ///// doesn't like this String value, but is OK with the "1234" as above.
      System.out.println("cell 2");
      System.out.println(cell2.getT().value());
      System.out.println("cell 1");
      System.out.println(cell.getT().value());
      row.getC().add(cell);
      row.getC().add(cell2);
      sheetData.getRow().add(row);
   }


In the code snip above, adding first cell "cell" had no problems, I added "cell2" with no problems using a different numeric value. But, when I changed "cell2" to be simply "ABC" for the value, it gives me grief, MS Excel gives me a warning stating it had to fix the sheet, then it shows the values in the cells as I expect them to be.

I would like to get rid of the MS Excel warning and ensure that the cells with text have no problems as do the cells with numeric-text do.

Any ideas?

I tried to make sense out of the following two links within the forum, but failed to grasp as to what really is required to just add "ABC" in and have it work in MS Excel without any alerts showing up.

http://www.docx4java.org/forums/xlsx-java-f15/adding-style-information-crashes-excel-t647.html
and
http://www.docx4java.org/forums/xlsx-java-f15/cells-with-character-values-t874.html

Do I really need this SharedStrings deal? If so, can someone assist me with, perhaps, provide a working sample that uses the SharedStrings? The code snip provided in the second URL given above didn't quite make sense to me. Seemed like a lot to go through to just add "ABC". Thus, I tried to follow it, but couldn't figure out how to apply it to my own code. Therefore, a working sample would help greatly in understanding how it is to be put together.

Thank you!

A

Re: Need help in adding a cell with "abc"

PostPosted: Tue Apr 24, 2012 3:08 am
by herolsen
Hi -- please see the updated post (xlsx-java-f15/cells-with-character-values-t874.html); I put in a comment on how to use inline strings so that you don't have to deal with shared.xml. That might be helpful.

Re: Need help in adding a cell with "abc"

PostPosted: Thu Apr 26, 2012 10:18 pm
by jason
Yep, there is another post somewhere in the forum which references the video http://openxmldeveloper.org/blog/b/open ... heets.aspx

Sorry you had to rediscover that... I've updated the sample code with references to this info