Commit 4626d53e authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Добавил выставление стиля ячейки + тестовый пример

ToDo добавить выставление стиля у всей строки/колонки

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@48006 954022d7-b5bf-4e40-9824-e11837661b57
parent 1ad5ff6f
......@@ -501,7 +501,7 @@
var styleName;
for (var i = 0; i < styles.defaultStyles.length; i++) {
styleName = styles.defaultStyles[i].asc_getName();
cellStyleContent += '<li id="'+styleName.replace(/\s/g,"")+'"index="'+i+'" class="SubItem fontListElement" style="font-family:Arial;" nameFont="'+styleName+'">'+styleName+'</li>';
cellStyleContent += '<li id="'+styleName.replace(/\s/g,"")+'"index="'+i+'" class="SubItem cellStyleListElement" nameStyle="'+styleName+'">'+styleName+'</li>';
}
$("#cellStyleSelect ul").empty().append(cellStyleContent);
});
......@@ -657,7 +657,15 @@
return false;
}});
$("#textMenu2").clickMenu({onClick:function(){
$('#textMenu2').trigger('closemenu');
if ($(this).hasClass("cellStyleListElement")){
$('#cellStyleSelectVal').text(this.innerHTML);
$('#cellStyleSelectVal').val(this.getAttribute("value"));
$('#cellStyleSelectVal').change();
api.asc_setCellStyle($(this).attr("nameStyle"));
}
return false;
}});
$("#dialogRenameWS").dialog({ autoOpen: false,
resizable: false, modal: true, closeOnEscape: false, dialogClass: 'dialogClass',
......
......@@ -70,6 +70,7 @@ var historyitem_Cell_SetStyle = 18;
var historyitem_Cell_SetFont = 19;
var historyitem_Cell_SetQuotePrefix = 20;
var historyitem_Cell_Angle = 21;
var historyitem_Cell_Style = 22;
var historyitem_DrawingObject_Add = 1;
var historyitem_DrawingObject_Remove = 2;
......
......@@ -2407,6 +2407,10 @@ UndoRedoCell.prototype = {
{
cell.setQuotePrefix(Val);
}
else if (historyitem_Cell_Style == Type)
{
cell.setCellStyle(Val);
}
}
};
......
......@@ -3876,6 +3876,7 @@ Woorksheet.prototype.getAllCol = function(){
function Cell(worksheet){
this.ws = worksheet;
this.sm = worksheet.workbook.oStyleManager;
this.cs = worksheet.workbook.CellStyles;
this.oValue = new CCellValue(this);
this.xfs = null;
this.tableXfs = null;
......@@ -4139,6 +4140,22 @@ Cell.prototype.getDefaultFormat=function(oDefault){
return col.xfs;
return oDefault;
};
Cell.prototype.setCellStyle=function(val){
var newVal = this.cs._prepareCellStyle(val);
var oRes = this.sm.setCellStyle(this, newVal);
if(History.Is_On() && oRes.oldVal != oRes.newVal) {
var oldStyleName = this.cs.getStyleNameByXfId(oRes.oldVal);
History.Add(g_oUndoRedoCell, historyitem_Cell_Style, this.ws.getId(), new Asc.Range(0, this.oId.getRow0(), gc_nMaxCol0, this.oId.getRow0()), new UndoRedoData_CellSimpleData(this.oId.getRow0(), this.oId.getCol0(), oldStyleName, val));
// Выставляем стиль
var oStyle = this.cs.getStyleByXfId(oRes.newVal);
this.setFont(oStyle.getFont());
this.setFill(oStyle.getFill());
this.setBorder(oStyle.getBorder());
}
this.bNeedCompileXfs = true;
this.oValue.cleanCache();
};
Cell.prototype.setNumFormat=function(val){
var oRes = this.sm.setNumFormat(this, val);
if(History.Is_On() && oRes.oldVal != oRes.newVal)
......@@ -4882,6 +4899,30 @@ Range.prototype.setValue2=function(array){
});
History.EndTransaction();
};
Range.prototype.setCellStyle=function(val){
History.Create_NewPoint();
var oBBox = this.bbox;
History.SetSelection(new Asc.Range(oBBox.c1, oBBox.r1, oBBox.c2, oBBox.r2));
this.createCellOnRowColCross();
var fSetProperty = this._setProperty;
var nRangeType = this._getRangeType();
if(c_oRangeType.All == nRangeType)
{
this.worksheet.getAllCol().setCellStyle(val);
fSetProperty = this._setPropertyNoEmpty;
}
fSetProperty.call(this, function(row){
if(c_oRangeType.All == nRangeType && null == row.xfs)
return;
row.setCellStyle(val);
},
function(col){
col.setCellStyle(val);
},
function(cell){
cell.setCellStyle(val);
});
};
Range.prototype.setNumFormat=function(val){
History.Create_NewPoint();
var oBBox = this.bbox;
......
......@@ -1252,6 +1252,15 @@ CCellStyles.prototype = {
}
return nCount;
},
getStyleByXfId: function (oXfId) {
for (var i = 0, length = this.CustomStyles.length; i < length; ++i) {
if (oXfId === this.CustomStyles[i].XfId) {
return this.CustomStyles[i];
}
}
return null;
},
getStyleNameByXfId: function (oXfId) {
var styleName = null;
if (null === oXfId)
......@@ -1283,6 +1292,48 @@ CCellStyles.prototype = {
return style.Name;
}
return null;
},
_prepareCellStyle: function (name) {
var defaultStyle = null;
var style = null;
var i, length;
var maxXfId = -1;
// Проверим, есть ли в default
for (i = 0, length = this.DefaultStyles.length; i < length; ++i) {
if (name === this.DefaultStyles[i].Name) {
defaultStyle = this.DefaultStyles[i];
break;
}
}
// Если есть в default, ищем в custom по builtinId. Если нет, то по имени
if (defaultStyle) {
for (i = 0, length = this.CustomStyles.length; i < length; ++i) {
if (defaultStyle.BuiltinId === this.CustomStyles[i].BuiltinId) {
style = this.CustomStyles[i];
break;
}
maxXfId = Math.max(maxXfId, this.CustomStyles[i].XfId);
}
} else {
for (i = 0, length = this.CustomStyles.length; i < length; ++i) {
if (name === this.CustomStyles[i].Name) {
style = this.CustomStyles[i];
break;
}
maxXfId = Math.max(maxXfId, this.CustomStyles[i].XfId);
}
}
// Если нашли, то возвращаем XfId
if (style)
return style.XfId;
if (defaultStyle) {
this.CustomStyles[i] = defaultStyle.clone();
this.CustomStyles[i].XfId = ++maxXfId;
return this.CustomStyles[i].XfId;
}
return null;
}
};
/** @constructor */
......@@ -1297,6 +1348,17 @@ function CCellStyle() {
this.xfs = null;
}
CCellStyle.prototype = {
clone: function () {
var oNewStyle = new CCellStyle();
oNewStyle.BuiltinId = this.BuiltinId;
oNewStyle.CustomBuiltin = this.CustomBuiltin;
oNewStyle.Hidden = this.Hidden;
oNewStyle.ILevel = this.ILevel;
oNewStyle.Name = this.Name;
oNewStyle.xfs = this.xfs.clone();
return oNewStyle;
},
getFill: function () {
if (null != this.xfs && null != this.xfs.fill)
return this.xfs.fill.bg;
......@@ -1368,6 +1430,27 @@ StyleManager.prototype =
xfs.align = new Align();
return xfs;
},
_prepareSetCellStyle : function (oItemWithXfs) {
return this._prepareSet(oItemWithXfs);
},
setCellStyle : function(oItemWithXfs, val)
{
// ToDo add code
var xfs = oItemWithXfs.xfs;
var oRes = {newVal: val, oldVal: null};
if(null != xfs && null != xfs.XfId)
oRes.oldVal = xfs.XfId;
else
oRes.oldVal = g_oDefaultXfId;
if(null == val) {
if(null != xfs)
xfs.XfId = g_oDefaultXfId;
} else {
xfs = this._prepareSetCellStyle(oItemWithXfs);
xfs.XfId = val;
}
return oRes;
},
setNumFormat : function(oItemWithXfs, val)
{
var xfs = oItemWithXfs.xfs;
......@@ -1852,6 +1935,7 @@ function Col(worksheet, index)
{
this.ws = worksheet;
this.sm = this.ws.workbook.oStyleManager;
this.cs = this.ws.workbook.CellStyles;
this.index = index;
this.id = this.ws.getNextColId();
this.BestFit = null;
......@@ -1981,6 +2065,10 @@ Col.prototype =
History.Add(g_oUndoRedoCol, historyitem_RowCol_SetStyle, this.ws.getId(), new Asc.Range(0, 0, gc_nMaxCol0, gc_nMaxRow0), new UndoRedoData_IndexSimpleProp(this.index, false, oldVal, newVal));
}
},
setCellStyle : function(val)
{
// ToDo add code here
},
setNumFormat : function(val)
{
var oRes = this.sm.setNumFormat(this, val);
......@@ -2113,6 +2201,7 @@ function Row(worksheet)
{
this.ws = worksheet;
this.sm = this.ws.workbook.oStyleManager;
this.cs = this.ws.workbook.CellStyles;
this.c = new Object();
this.id = this.ws.getNextRowId();
this.r = null;
......@@ -2239,6 +2328,10 @@ Row.prototype =
History.Add(g_oUndoRedoRow, historyitem_RowCol_SetStyle, this.ws.getId(), new Asc.Range(0, this.index, gc_nMaxCol0, this.index), new UndoRedoData_IndexSimpleProp(this.index, true, oldVal, newVal));
}
},
setCellStyle : function(val)
{
// ToDo add code here
},
setNumFormat : function(val)
{
var oRes = this.sm.setNumFormat(this, val);
......
......@@ -7115,7 +7115,7 @@
}
break;
case "style":
// ToDo add code here
range.setCellStyle(val); canChangeColWidth = c_oAscCanChangeColWidth.numbers; break;
break;
case "paste":
var pasteExec = function()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment