*/
data : false,
/**
- * @cfg {String} downloadUrl where GnumerictoExcel.php is...
+ * @cfg {String} downloadURL where GnumerictoExcel.php is...
*/
- downloadUrl : false,
+ downloadURL : false,
/**
* @type {XmlDocument} doc the gnumeric xml document
* @type {XmlNode} sheet the 'Sheet' element
*/
sheet : false,
+
+ /**
+ * @type {XmlNode} sheet the 'Cells' element
+ */
+ cellholder : false,
/**
* @type {Object} grid the map[row][col] = cellData
*/
* @type {String} stylesheetID id of stylesheet created to render spreadsheat
*/
stylesheetID : false,
+ /**
+ * @type {Number} rowOffset - used by table importer to enable multiple tables to be improted
+ */
+
+ rowOffset : 0,
+
/**
* load:
* run the connection, parse document and fire load event..
this.cmax = 1;
this.sheet = _t.doc.getElementsByTagNameNS('*','Sheet')[0];
+
+
+ this.cellholder = this.sheet.getElementsByTagNameNS('*','Cells')[0];
var cells = this.sheet.getElementsByTagNameNS('*','Cell');
/**
* set:
* Set the value of a cell..
- * @param {String} cell name of cell, eg. C10
+ * @param {String} cell name of cell, eg. C10 or { c: 1, r :1 }
+
* @param {Value} value to put in cell..
+ * @param {ValueType} type of value
+ * @param {ValueFormat} value format of cell
*
* Cells should exist at present, we do not make them up...
*/
- set : function(cell, v) {
+ set : function(cell, v, vt, vf) {
var cs= typeof(cell) == 'string' ? this.toRC(cell) : cell;
- //Roo.log( this.grid[cs.r][cs.c]);
+ //Roo.log( cs.r+ ',' + cs.c + ' = '+ v);
// need to generate clell if it doe
if (typeof(this.grid[cs.r]) == 'undefined') {
Roo.log('no row:' + cell);
- return
+ this.grid[cs.r] = []; // create a row..
+ //return;
+ }
+ if (typeof(this.grid[cs.r][cs.c]) == 'undefined') {
+ Roo.log('cell not defined:' + cell);
+ this.createCell(cs.r,cs.c);
}
if (typeof(this.grid[cs.r][cs.c].dom) == 'undefined') {
Roo.log('no default content for cell:' + cell);
- return;
+ this.createCell(cs.r,cs.c);
+ //return;
}
this.grid[cs.r][cs.c].value= v;
-
this.grid[cs.r][cs.c].dom.textContent= v;
+ if (typeof(vt != 'undefined') && vt) {
+ this.grid[cs.r][cs.c].valueType = vt;
+ this.grid[cs.r][cs.c].dom.setAttribute('ValueType', vt);
+ }
+ if (typeof(vf != 'undefined') && vf) {
+ this.grid[cs.r][cs.c].valueFormat = vf;
+ this.grid[cs.r][cs.c].dom.setAttribute('ValueFormat', vf);
+ }
+
},
copyRow : function(src, dest) {
- var old = this.grid[src];
- this.grid[dest] = {}
+ if (dest == src) {
+ return;
+ }
+ // Roo.log('create Row' + dest);
+ if (typeof(this.grid[dest]) == 'undefined') {
+ this.grid[dest] = {}
+ }
+
for (var c = 0; c < this.cmax; c++) {
this.copyCell({ r: src, c: c } , { r: dest, c: c});
}
+ this.rmax = Math.max(this.rmax, dest +1);
+
+ },
+
+ createCell: function(r,c)
+ {
+ //<gnm:Cell Row="6" Col="5" ValueType="60">Updated</gnm:Cell>
+ var nc = this.doc.createElementNS('http://www.gnumeric.org/v10.dtd', 'gnm:Cell');
+ this.cellholder.appendChild(nc);
+ var lb = this.doc.createTextNode("\n");// add a line break..
+ this.cellholder.appendChild(lb);
+
+ nc.setAttribute('Row', new String(r));
+ nc.setAttribute('Col', new String(c));
+ nc.setAttribute('ValueType', '60');
+ nc.textContent = '';
+ this.grid[r][c] = Roo.applyIf({
+ valueType : '60',
+ valueFormat : '',
+ value : '',
+ dom: nc,
+ r: r,
+ c: c
+ }, _t.defaultCell);
+
+ return nc;
+
},
+
copyCell : function(src, dest)
{
var old = this.grid[src.r][src.c];
// is it an alias...
if ((old.c != src.c) || (old.r != src.r)) {
// only really works on horizonatal merges..
+
this.grid[dest.r][dest.c] = this.grid[desc.r][old.c]; // let's hope it exists.
return;
}
var nc = Roo.apply({}, this.grid[src.r][src.c]);
+
nc.value = '';
- if (old.dom) {
- Roo.log("No cell for " + Roo.encode(src));
+ if (typeof(old.dom) == 'undefined') {
+ Roo.log("No cell to copy for " + Roo.encode(src));
return;
}
-
+ this.grid[dest.r][dest.c] = nc;
nc.dom = old.dom.cloneNode(true);
- nc.dom.setAttribute('row', dest.r);
- nc.dom.setAttribute('cell', dest.c);
+ nc.dom.setAttribute('Row', dest.r);
+ nc.dom.setAttribute('Cell', dest.c);
nc.dom.textContent = '';
old.dom.parentNode.appendChild(nc.dom);
if (!old.styles || !old.styles.length) {
return;
}
+ //Roo.log("DEST");
+ //Roo.log(dest);
+ //Roo.log("STYLES");
// .styles...
Roo.each(old.styles, function(s) {
- // duplidate the style..
- var ns = s.cloneNode(true);
+ // try and extend existing styles..
+ var er = s.getAttribute('endRow') * 1;
+ var ec = s.getAttribute('endCol') * 1;
+ //Roo.log(s);
+ if (dest.r == er) {
+ s.setAttribute('endRow', dest.r + 1);
+ }
+ if (dest.c == ec) {
+ s.setAttribute('endCol', dest.c + 1);
+ }
+ /*var ns = s.cloneNode(true);
s.parentNode.appendChild(ns);
ns.setAttribute('startCol', dest.c);
ns.setAttribute('startRow', dest.r);
ns.setAttribute('endCol', dest.c + 1);
ns.setAttribute('endRow', dest.r +1);
-
+ */
});
},
}
}
+ },
+ // now the rows..
+ importTable : function (datagrid, xoff,yoff)
+ {
+ if (!datagrid) {
+ Roo.log("Error table not found!?");
+ return;
+ }
+ xoff = xoff || 0;
+ yoff = yoff || 0;
+
+ var cleanHTML = function (str) {
+
+ var ret = str;
+ ret = ret.replace(/ /g,'.');
+ ret = ret.replace(/\n/g,'.');
+ ret = ret.replace(/\r/g,'.');
+ var i;
+ while (-1 != (i = ret.indexOf(unescape('%A0')))) {
+ ret = ret.substring(0,i) + ' ' + ret.substring(i+1,str.length);
+ }
+ return ret;
+ };
+
+
+ // <cell col="A" row="1">Test< / cell>
+ // <cell col="B" row="2" type="Number" format="test1">30< / cell>
+ var rowOffsets = [];
+ var rows = datagrid.getElementsByTagName('tr');
+ //alert(rows.length);
+
+ for(var row=0;row<rows.length;row++) {
+ //var style = document.defaultView.getComputedStyle(rows[row], "");
+
+ //if (rows[row].getAttribute('xls:height')) {
+ // this.setRowHeight(row+y_offset, 0 + rows[row].getAttribute('xls:height'));
+ //} else {
+ // this.setRowHeight(row+y_offset, 0 + style.height.replace(/[^0-9.]+/g,''));
+ // }
+
+ //var coloffset = 0;
+ // if (rowOffsets[row]) {
+ // coloffset += rowOffsets[row];
+ // }
+ var cols = rows[row].getElementsByTagName('td');
+
+
+ for(var col=0;col < cols.length; col++) {
+
+
+ //var colat = col + coloffset;
+ /*
+ if (cols[col].getAttribute('colspan') && (cols[col].getAttribute('colspan') > 1)) {
+
+
+ this.mergeRegion(
+ colat,
+ row +y_offset,
+ colat + (cols[col].getAttribute('colspan') - 1),
+ row+y_offset + (
+ (cols[col].getAttribute('rowspan') > 1) ?
+ (cols[col].getAttribute('rowspan') - 1) : 0
+ )
+ );
+
+
+
+ coloffset += (cols[col].getAttribute('colspan') - 1);
+ }
+
+ if (cols[col].getAttribute('rowspan') && (cols[col].getAttribute('rowspan') > 1)) {
+ // this should really do a merge, but it's pretty damn complex...
+ //this.mergeRegion(colat,row +y_offset,colat + (cols[col].getAttribute('colspan') - 1), row+y_offset);
+ var rroff = cols[col].getAttribute('colspan') ? (cols[col].getAttribute('colspan') -0): 1;
+ var rr = 0;
+ for (rr = 0; rr < cols[col].getAttribute('rowspan');rr++) {
+ rowOffsets[rr + row] = col + rroff;
+ }
+
+ }
+ */
+
+ /*
+ var style = this.newStyle();
+ if (style.setFrom(cols[col])) {
+ style.add(
+ colat+x_offset,
+ row+y_offset,
+
+ colat+x_offset + ((cols[col].getAttribute('colspan') > 1) ?
+ (cols[col].getAttribute('colspan') - 1) : 0),
+ row+y_offset + ((cols[col].getAttribute('rowspan') > 1) ?
+ (cols[col].getAttribute('rowspan') - 1) : 0)
+ );
+ }
+
+ */
+ // skip blank cells
+ if (!cols[col].childNodes.length) {
+ continue;
+ }
+
+
+
+
+ var vt = '60';
+ var vf = false;
+
+ switch(cols[col].getAttribute('xls:type')) {
+ case 'int':
+ vt = 30; // int!!!!
+ break;
+
+ case 'float':
+ vt = 40; // float!!!!
+ if (cols[col].getAttribute('xls:floatformat')) {
+ vf = cols[col].getAttribute('xls:floatformat');
+ }
+ break;
+
+ case 'date':
+ vt = 30;
+ //ValueFormat="d/m/yyyy" 38635
+ var vf = 'd/m/yyy';
+ if (cols[col].getAttribute('xls:dateformat')) {
+ vf= cols[col].getAttribute('xls:dateformat');
+ }
+
+
+
+ break;
+
+ default:
+
+ break;
+ }
+ /*
+ if (cols[col].getAttribute('xls:src')) {
+ //alert(cols[col].childNodes[0].width);
+ if (this.writeImage(
+ row+y_offset,
+ colat+x_offset+coloffset,
+ cols[col].getAttribute('xls:src'),
+ cols[col].childNodes[0].width,
+ cols[col].childNodes[0].height
+ )) {
+
+ }
+ continue;
+ }
+ */
+
+ if (!cols[col].childNodes[0].nodeValue) {
+ continue;
+ }
+ if (!cols[col].childNodes[0].nodeValue.replace(/^\s*|\s*$/g,"").length) {
+ continue;
+ }
+ // strip me.!
+ var cell_value_text = cleanHTML(cols[col].childNodes[0].nodeValue);
+
+ if (cols[col].getAttribute('xls:percent')) {
+ cell_value_text = '' + ((cell_value_text * 1) / 100);
+ }
+
+ if (cell_value_text.length && (vt == 30)) {
+ var bits = cell_value_text.split(/-/);
+ var cur = new Date(bits[0],bits[1]-1,bits[2]);
+ cell_value_text = '' + Math.round((cur.getTime() - Date.UTC(1899,11,30)) / (24 * 60 * 60 * 1000));
+ }
+
+
+
+ if (cols[col].getAttribute('xls:formula')) {
+ var s = cols[col].getAttribute('xls:formula');
+ cell.removeAttribute('ValueType');
+ cell_value_text = s.replace(/#row#/g,(row + y_offset + 1));
+ }
+ this.set({ r: row + yoff, c : col + xoff }, cell_value_text, vt, vf);
+
+
+
+
+
+ }
+ }
+ this.rowOffset += rows.length;
+
},
+
/**
* toHTML:
{
name = name || "Missing_download_filename";
+ if (this.downloadURL && this.downloadURL.charAt(this.downloadURL .length-1) != '/') {
+ this.downloadURL += '/';
+ }
+
var ser = new XMLSerializer();
var x = new Pman.Download({
method: 'POST',
debug : 0
},
- url : (this.downloadUrl || (baseURL + '/GnumericToExcel/')) + name + '.xls',
+ url : (this.downloadURL || (baseURL + '/GnumericToExcel/')) + name + '.xls',
success : function() {
Roo.MessageBox.alert("Alert", "File should have downloaded now");
if (callback) {