3636
3737import com .maxprograms .xml .Document ;
3838import com .maxprograms .xml .Element ;
39- import com .maxprograms .xml .Indenter ;
4039import com .maxprograms .xml .SAXBuilder ;
4140import com .maxprograms .xml .XMLOutputter ;
4241
@@ -88,7 +87,6 @@ private void setSheetName(File folder, String name) throws SAXException, IOExcep
8887 try (FileOutputStream out = new FileOutputStream (workbook )) {
8988 XMLOutputter outputter = new XMLOutputter ();
9089 outputter .preserveSpace (true );
91- Indenter .indent (root , 2 );
9290 outputter .output (doc , out );
9391 }
9492 }
@@ -101,6 +99,16 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti
10199
102100 File sheetXml = new File (folder , "xl" + SEP + "worksheets" + SEP + "sheet1.xml" );
103101 Document sheetDoc = builder .build (sheetXml );
102+ Element columns = sheetDoc .getRootElement ().getChild ("cols" );
103+ columns .setContent (new ArrayList <>());
104+ for (int i = 0 ; i < sheet .getColumns ().size (); i ++) {
105+ Element col = new Element ("col" );
106+ col .setAttribute ("min" , "" + (i + 1 ));
107+ col .setAttribute ("max" , "" + (i + 1 ));
108+ col .setAttribute ("width" , "80" );
109+ col .setAttribute ("customWidth" , "1" );
110+ columns .addContent (col );
111+ }
104112 Element sheetData = sheetDoc .getRootElement ().getChild ("sheetData" );
105113 sheetData .setContent (new ArrayList <>());
106114
@@ -136,6 +144,7 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti
136144 Element c = new Element ("c" );
137145 c .setAttribute ("r" , columnIndex .get (colCount ) + (i + 1 ));
138146 c .setAttribute ("t" , "s" );
147+ c .setAttribute ("s" , "1" );
139148 Element v = new Element ("v" );
140149 v .addContent ("" + unique .get (cell ));
141150 c .addContent (v );
@@ -153,13 +162,11 @@ private void setStrings(File folder, Sheet sheet) throws SAXException, IOExcepti
153162 try (FileOutputStream out = new FileOutputStream (sharedStrings )) {
154163 XMLOutputter outputter = new XMLOutputter ();
155164 outputter .preserveSpace (true );
156- Indenter .indent (sst , 2 );
157165 outputter .output (stringsDoc , out );
158166 }
159167 try (FileOutputStream out = new FileOutputStream (sheetXml )) {
160168 XMLOutputter outputter = new XMLOutputter ();
161169 outputter .preserveSpace (true );
162- Indenter .indent (sheetDoc .getRootElement (), 2 );
163170 outputter .output (sheetDoc , out );
164171 }
165172 }
0 commit comments