我这儿还是不行,是这样的。我们现在的需求是让这个表格的大小适应到整个div的大小。下面是代码:function zoom_excel() {
var sheet = spread.getActiveSheet();
var div = document.getElementById('ss');
var divWidth = div.clientWidth || div.offsetWidth || div.scrollWidth;
var divHeight = div.clientHeight || div.offsetHeight || div.scrollHeight;
var colCount = sheet.getColumnCount();
var rowCount = sheet.getRowCount();
var sheetWidth = 0 ;
var sheetHeight = 0 ;
for (var i = 0; i < colCount; i++) {
var span = sheet.getSpan(0, i);
var currentCount = 1;
if (span != null) {
currentCount = span.colCount;
}
var rectWidth = sheet.getCellRect(0, i).width;
if (rectWidth != null) {
sheetWidth += rectWidth;
} else {
sheetWidth += sheet.getColumnWidth(0, i);
}
i += (currentCount - 1);
}
for (var i = 0; i < rowCount; i++) {
var span = sheet.getSpan(i, 0);
var currentCount = 1;
if (span != null) {
currentCount = span.rowCount;
}
var rectHeight = sheet.getCellRect(i, 0).height;
if (rectHeight != null) {
sheetHeight += rectHeight;
} else {
sheetHeight += sheet.getRowHeight(i,0);
}
i += (currentCount - 1);
}
if (sheetHeight > sheetWidth) {
sheet.zoom((divWidth-30) / sheetWidth);
} else {
sheet.zoom((divHeight-30) / sheetHeight);
}
}
|