Skip to content

Commit

Permalink
writer fixed some parts, now the files can be opened in openoffice, b…
Browse files Browse the repository at this point in the history
…ut not in excel
  • Loading branch information
thomashoffmann1979 committed Jan 31, 2014
1 parent bb1604d commit 421fa74
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 35 deletions.
13 changes: 10 additions & 3 deletions lib/reader/xlsxreader.js
Expand Up @@ -78,6 +78,8 @@ XLSXReader.prototype.open = function (config,cb){
}
zip = new Zip(this.filename);
this.zipEntries = zip.getEntries();


this._openCallback = cb;


Expand All @@ -103,9 +105,14 @@ XLSXReader.prototype.getEntry=function(filename){

XLSXReader.prototype.onContentReady = function(){
//console.log('content ready');
this.stringReader.data = this.getEntry(this.contentReader.strings[0]).toString();
this.stringReader.on('ready',this.onStringReady.bind(this));
this.stringReader.parse();
//console.log(this.contentReader);//.strings[0]
if (this.contentReader.strings>0){
this.stringReader.data = this.getEntry(this.contentReader.strings[0]).toString();
this.stringReader.on('ready',this.onStringReady.bind(this));
this.stringReader.parse();
}else{
this.onStringReady();
}
}


Expand Down
5 changes: 3 additions & 2 deletions lib/writer/xlsx/app.js
Expand Up @@ -43,7 +43,7 @@ AppWriter.prototype.process = function(){
xml.addElement('ScaleCrop','false');


head = xml.addElement('HeadingPairs','false');
head = xml.addElement('HeadingPairs');

vector = head.addElement('vt:vector').addAttribute('size','2').addAttribute('baseType','variant');
vector.addElement('vt:variant').addElement('vt:lpstr','Worksheets')
Expand All @@ -53,14 +53,15 @@ AppWriter.prototype.process = function(){
vector = title.addElement('vt:vector').addAttribute('baseType','lpstr').addAttribute('size','1');
vector.addElement('vt:lpstr','Blatt1')

xml.addElement('Manager');
xml.addElement('Company','my firm');

xml.addElement('LinksUpToDate','false');
xml.addElement('SharedDoc','false');
xml.addElement('HyperlinksChanged','false');
xml.addElement('AppVersion','12.0000');

me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);

fileName = '/docProps/app.xml';
me._writer.zip.addFile(fileName.replace(/^\//,''),new Buffer(me._data,'utf8'));
Expand Down
5 changes: 3 additions & 2 deletions lib/writer/xlsx/content.js
Expand Up @@ -39,16 +39,17 @@ ContentWriter.prototype.process = function(){
xml.addElement('Default')
.addAttribute('Extension','rels')
.addAttribute('ContentType','application/vnd.openxmlformats-package.relationships+xml');
/*
xml.addElement('Default')
.addAttribute('Extension','jpeg')
.addAttribute('ContentType','image/jpeg');

*/
for(i in me._parts){
xml.addElement('Override')
.addAttribute('PartName',me._parts[i].PartName)
.addAttribute('ContentType',me._parts[i].ContentType);
}
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);

fileName = '/[Content_Types].xml';
me._writer.zip.addFile(fileName.replace(/^\//,''),new Buffer(me._data,'utf8'));
Expand Down
9 changes: 5 additions & 4 deletions lib/writer/xlsx/core.js
Expand Up @@ -40,15 +40,16 @@ CoreWriter.prototype.process = function(){

xml.addElement('dc:creator','Sheeter');
xml.addElement('cp:lastModifiedBy','Sheeter');
xml.addElement('dcterms:created','2014-01-30T09:59:52Z').addAttribute('xsi:type','dcterms:W3CDTF');
xml.addElement('dcterms:modified','2014-01-30T10:01:17Z').addAttribute('xsi:type','dcterms:W3CDTF');
xml.addElement('dcterms:created','2014-01-30T09:59:52.000Z').addAttribute('xsi:type','dcterms:W3CDTF');
xml.addElement('dcterms:modified','2014-01-30T10:01:17.000Z').addAttribute('xsi:type','dcterms:W3CDTF');
/*
xml.addElement('dc:title','Sheeter - title');
xml.addElement('dc:subject','Sheeter - subject');
xml.addElement('dc:description','Sheeter - description');
xml.addElement('cp:keywords','Sheeter - keywords');
xml.addElement('cp:category','Sheeter - category');

me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
*/
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);


fileName = '/docProps/core.xml';
Expand Down
2 changes: 1 addition & 1 deletion lib/writer/xlsx/docrels.js
Expand Up @@ -40,7 +40,7 @@ DocumentRelationWriter.prototype.process = function(){
.addAttribute('Type',me._rels[i].Type)
.addAttribute('Target',me._rels[i].Target);
}
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);

fileName = '/_rels/.rels';
me._writer.zip.addFile(fileName.replace(/^\//,''),new Buffer(me._data,'utf8'));
Expand Down
23 changes: 15 additions & 8 deletions lib/writer/xlsx/main.js
Expand Up @@ -25,15 +25,21 @@ MainWriter.prototype.process=function(){
var me = this;

me._data = '';
me._data += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n";
me._data += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
me._xml.addAttribute('xmlns','http://schemas.openxmlformats.org/spreadsheetml/2006/main');
me._xml.addAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships');

me._xml.addElement('workbookPr')
.addAttribute('codeName','ThisWorkbook');
.addAttribute('defaultThemeVersion','124226');

me._xml.addElement('bookViews')
.addElement('workbookView')
.addAttribute('xWindow','480')
.addAttribute('yWindow','60')
.addAttribute('windowWidth','18195')
.addAttribute('windowHeight','8505');
/*
xWindow="480" yWindow="60" windowWidth="18195" windowHeight="8505"/
.addAttribute('activeTab','0')
.addAttribute('autoFilterDateGrouping','1')
.addAttribute('minimized','0')
Expand All @@ -42,19 +48,20 @@ MainWriter.prototype.process=function(){
.addAttribute('tabRatio','600')
.addAttribute('showVerticalScroll','1')
.addAttribute('visibility','visibility');

*/

me._xml.addElement('fileVersion')
.addAttribute('appName','xl')
.addAttribute('lastEdited','4')
.addAttribute('lowestEdited','4')
.addAttribute('rupBuild','4505')
.addAttribute('lastEdited','5')
.addAttribute('lowestEdited','5')
.addAttribute('rupBuild','9303')

me._xml.addElement('calcPr')
.addAttribute('calcId','1')
.addAttribute('calcId','145621');
/*
.addAttribute('calcMode','auto')
.addAttribute('fullCalcOnLoad','1');
*/
me._sheetWriter.on('ready',me.sheetReady.bind(me));
me.sheetReady();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/writer/xlsx/rels.js
Expand Up @@ -40,7 +40,7 @@ RelationWriter.prototype.process = function(){
.addAttribute('Type',me._rels[i].Type)
.addAttribute('Target',me._rels[i].Target);
}
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);



Expand Down
20 changes: 19 additions & 1 deletion lib/writer/xlsx/sheet.js
Expand Up @@ -45,20 +45,30 @@ SheetWriter.prototype.process = function(sheet,index){
xml.addAttribute('xmlns','http://schemas.openxmlformats.org/spreadsheetml/2006/main');
xml.addAttribute('xmlns:r','http://schemas.openxmlformats.org/officeDocument/2006/relationships');
xml.addAttribute('xmlns:mc','http://schemas.openxmlformats.org/markup-compatibility/2006');

xml.addAttribute('mc:Ignorable','x14ac');
xml.addAttribute('xmlns:x14ac','http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac');

xml.addElement('dimension')
.addAttribute('ref',sheeter_utils.columnStringFromIndex(dim.min_column)+dim.min_row+':'+sheeter_utils.columnStringFromIndex(dim.max_column)+dim.max_row);

xml.addElement('sheetViews').addElement('sheetView').addAttribute('workbookViewId','0');
xml.addElement('sheetFormatPr').addAttribute('defaultRowHeight','15')
.addAttribute('x14ac:dyDescent','0.25');

sd = xml.addElement('sheetData');

for(r=0,m=byRow.length; r<m; r+=1){
rd = sd.addElement('row');
rd.addAttribute('r',(r+1));
rd.addAttribute('x14ac:dyDescent','0.25');

row = byRow[r];
for(c=0,cc=row.length; c<cc; c+=1){
if (row[c] != null){
cd = rd.addElement('c');
cd.addAttribute('r',row[c].id);
cd.addAttribute('s','1');
if (typeof row[c].value == 'number'){
cd.addElement('v',row[c].value);
}else{
Expand All @@ -72,7 +82,15 @@ SheetWriter.prototype.process = function(sheet,index){
}
}

me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);

xml.addElement('pageMargins')
.addAttribute('left','0.7')
.addAttribute('right','0.7')
.addAttribute('top','0.75')
.addAttribute('bottom','0.75')
.addAttribute('header','0.3')
.addAttribute('footer','0.3');
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);

fileName = '/xl/worksheets/sheet'+index+'.xml';
relId = me._relation.addRelation('http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet',fileName.replace(/^\/xl\//,''));
Expand Down
17 changes: 13 additions & 4 deletions lib/writer/xlsx/strings.js
Expand Up @@ -11,6 +11,7 @@ var StringWriter = function(writer){
this._relation = writer.relationWriter;
this._strings = [];
this._stringsIndex = -1;
this._stringsCount = 0;
}


Expand All @@ -22,6 +23,8 @@ sheeter_utils.inherits(StringWriter,EventEmitter,{

StringWriter.prototype.add=function(str){
var i = this._strings.indexOf(str);

this._stringsCount += 1;
if (i < 0){
this._strings.push(str);
return this._strings.length - 1;
Expand All @@ -37,26 +40,32 @@ StringWriter.prototype.process=function(){
fileName,
relId;

if (this._strings.length>0){

me._data = '';
me._data += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n";
me._data += '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';

xml.addAttribute('xmlns','http://schemas.openxmlformats.org/spreadsheetml/2006/main');
xml.addAttribute('count',this._strings.length);
xml.addAttribute('count',this._stringsCount);
xml.addAttribute('uniqueCount',this._strings.length);

if (this._strings.length>0){
for( i in this._strings ){
xml.addElement('si')
.addElement('t',this._strings[i])
}
}else{

xml.addElement('si')
.addElement('t')
}
me._data += xml.toXMLString(true);

fileName = '/xl/sharedStrings.xml';
me._contents.addPart(fileName,'application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml');
relId = me._relation.addRelation('http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings',fileName.replace(/^\/xl\//,''));

me._writer.zip.addFile(fileName.replace(/^\//,''),new Buffer(me._data,'utf8'));
}

me.emit('ready',me,relId,fileName);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/writer/xlsx/styles.js
Expand Up @@ -89,7 +89,7 @@ StylesWriter.prototype.process = function(){
.addAttribute('defaultTableStyle','TableStyleMedium9')
.addAttribute('defaultPivotStyle','PivotStyleMedium4');

me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);
console.log(me._data);


Expand Down
4 changes: 3 additions & 1 deletion lib/writer/xlsx/theme.js
Expand Up @@ -120,13 +120,15 @@ ThemeWriter.prototype.process = function(){
xml.addElement('a:objectDefaults');
xml.addElement('a:extraClrSchemeLst');

me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+"\r\n" + xml.toXMLString(true);
me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' + xml.toXMLString(true);
console.log('theme',me._data);


fileName = '/xl/theme/theme1.xml';
me._contents.addPart(fileName,'application/vnd.openxmlformats-officedocument.theme+xml');
relId = me._relation.addRelation('http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme',fileName.replace(/^\/xl\//,''));
//me._data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS P????"/><a:font script="Hang" typeface="?? ??"/><a:font script="Hans" typeface="??"/><a:font script="Hant" typeface="????"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS P????"/><a:font script="Hang" typeface="?? ??"/><a:font script="Hans" typeface="??"/><a:font script="Hant" typeface="????"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/><a:font script="Geor" typeface="Sylfaen"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera><a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>';

me._writer.zip.addFile(fileName.replace(/^\//,''),new Buffer(me._data,'utf8'));
me.emit('ready',me,relId,fileName);
}
Expand Down

0 comments on commit 421fa74

Please sign in to comment.