这个目前支持不了。
/**
* 客户端宏
* 对象:spreadsheetReport
* 事件:onRenderReport
*/
可以用下面这个宏尝试:
function main(spreadsheetReport) {
// 数据条位置配置信息,key为sheet名称或者照相机的名称
// 例如"标题"表示对"标题"sheet页进行配置
var config = {
"Sheet1": [{
// 数据条的区域
area: {
start: "D2"
},
// 数据条的位置:MID表示单元格中点值对齐,AUTO表示自动
position: "MID"
}]
};
spreadsheetReport.processConditionalFormattingsHTMLs_0331 = spreadsheetReport.processConditionalFormattingsHTMLs;
spreadsheetReport.processConditionalFormattingsHTMLs = function (win) {
var data = buildDataBarPositionData.call(this, config, win)
var ret = spreadsheetReport.processConditionalFormattingsHTMLs_0331.apply(this, arguments);
resetDataBarPositionData.call(this, data)
return ret;
};
}
// 重置数据条的位置
function resetDataBarPositionData(data) {
if (!data || !data.result || data.result.length == 0) {
return;
}
var result = data.result;
for (var i = 0; i < result.length; i++) {
result[i].td.style.backgroundPosition = result[i].marginLeft + "px" + " 50%";
result[i].td._resetDataBarProcessed = true;
}
for (var i = 0; i < data.noneImageTdArray.length; i++) {
/*if (data.options[i] !== "MID") {
continue;
}*/
for (var j = 0; j < data.noneImageTdArray[i].length; j++) {
var td = data.noneImageTdArray[i][j];
if (!td.style.background || td._resetDataBarProcessed) {
continue;
}
if (util.trim(td.innerHTML) == "0") {
td.style.backgroundSize = "auto";
td.style.backgroundPosition = "center";
//if (data.options[i] !== "MID") {
td.style.backgroundPosition = "-10000px 50%";
//}
}
}
}
}
// 重置数据条的位置的数据
function buildDataBarPositionData(config, win) {
var htmls = win.conditionalFormattingsHTMLs;
var cellRange = win.cellRange || [0, 0, 0, 0];
if (!htmls || !win.frameElement) {
return;
}
// sheet
var sheetName = this.sheetNames[this.currentSheetIndex];
var name;
if (win.frameElement == this.elemSheetFrame) {
name = sheetName;
} else {
if (!win.frameElement.isCamera) {
return;
}
name = sheetName + "/" + win.frameElement.name;
}
var options = config[name];
if (!options) {
return;
}
var tdArray = [];
var imgWidths = [];
var noneImageTdArray = [];
for (var key in htmls) {
var val = htmls[key];
var p = this.parseCellIndex(key);
var optionIndx = findMatchedOptionIndex.call(this, options, p);
if (optionIndx === undefined) {
continue;
}
var td = this.getFrameCell(win, p[0] - cellRange[0] + cellRange[2], p[1] - cellRange[1] + cellRange[3]);
if (!td) {
continue;
}
var img = td.getElementsByTagName("IMG")[0];
if (img) {
putArray(tdArray, optionIndx, td);
putArray(imgWidths, optionIndx, img.clientWidth);
} else {
putArray(noneImageTdArray, optionIndx, td);
}
}
var result = [];
for (var i = 0; i < tdArray.length; i++) {
if (!tdArray[i]) {
continue;
}
var position = options[i].position;
var tdValues = [];
for (var j = 0; j < tdArray[i].length; j++) {
var valueTd = tdArray[i][j].getElementsByTagName("TD")[0];
if (!valueTd) {
continue;
}
var val = util.trim(valueTd.innerHTML);
tdValues[j] = val;
if (position == "MID") {
var tdWidth = valueTd.clientWidth;
var marginLeft = val.indexOf("-") == 0 ?
tdWidth/2 - imgWidths[i][j] - 1: tdWidth/2 - 1;
if (val == "0") {
marginLeft = 0;
}
result.push({
td: tdArray[i][j],
marginLeft: marginLeft
});
}
}
if (position !== "MID") {
var max = 0;
for (var m = 0; m < tdValues.length; m++) {
if (tdValues[m].indexOf("-") == 0) {
max = Math.max(max, imgWidths[i][m]);
}
}
for (var j = 0; j < tdArray[i].length; j++) {
result.push({
td: tdArray[i][j],
marginLeft: (tdValues[j].indexOf("-") == 0 ?
max - imgWidths[i][j] : max)
})
}
}
}
return {
result: result,
noneImageTdArray: noneImageTdArray,
options: options
};
}
function putArray(arr, index, val) {
if (!arr[index]) {
arr[index] = [];
}
arr[index] .push(val);
}
function findMatchedOptionIndex(options, p) {
for (var i = 0; i < options.length; i++) {
var option = options[i];
if (!option.area || !option.area.start) {
continue;
}
var start = option.area._$start;
if (!start) {
start = this.parseCellIndex(option.area.start);
option.area._$start = start;
}
if (p[0] >= start[0] && p[1] == start[1]) {
return i;
}
}
} |