v1.2.3
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Version 1.2.2
|
||||
// Version 1.2.3
|
||||
|
||||
Function TOfficeObj(n);
|
||||
Begin
|
||||
@@ -487,7 +487,7 @@ type TFont=class(NodeInfo)
|
||||
,("field":"Strikethrough","name":"strike","obj":XMLStrikethrough,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"")
|
||||
,("field":"Script","name":"vertAlign","obj":XMLScript,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
,("field":"Charset","name":"charset","obj":XMLCharset,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
,("field":"Underline","name":"u","obj":XMLUnderline,"attrEx":"","nodeType":"empty_string","attrName":"", "desc":"", "class":"")
|
||||
,("field":"Underline","name":"u","obj":XMLUnderline,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
,("field":"FontStyle","name":"fontstyle","obj":FontStyle,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
,("field":"OutlineFont","name":"outlinefont","obj":OutlineFont,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
,("field":"Shadow","name":"shadow","obj":Shadow,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
|
||||
@@ -4489,22 +4489,6 @@ type TStyle=class(NodeInfo)
|
||||
) union ExtNodes;
|
||||
End;
|
||||
|
||||
Function Apply();
|
||||
Begin
|
||||
children := GetChildren();
|
||||
for i:=0 to length(children)-1 do
|
||||
begin
|
||||
obj := children[i]["obj"];
|
||||
if ifObj(obj) then
|
||||
begin
|
||||
root := obj.Root();
|
||||
if not ifObj(root) then continue;
|
||||
marshal := obj.Marshal();
|
||||
class(TSXml).UpdateNode(root, marshal["attributes"], marshal["children"]);
|
||||
end
|
||||
end
|
||||
End;
|
||||
|
||||
//Attributes
|
||||
|
||||
//Nodes
|
||||
@@ -14881,3 +14865,4 @@ Begin
|
||||
return true;
|
||||
return false;
|
||||
End;
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +1,4 @@
|
||||
// Version 1.2.2
|
||||
// Version 1.2.3
|
||||
|
||||
Type TSDocxFile = Class
|
||||
///Version: V1.0 2022-09-20
|
||||
@@ -487,3 +487,4 @@ private
|
||||
numberingObj_;
|
||||
DocPrId_;
|
||||
End;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Version 1.2.2
|
||||
// Version 1.2.3
|
||||
|
||||
Type TSExcelFile = Class
|
||||
///Version: V1.0 2022-08-08
|
||||
@@ -57,7 +57,7 @@ Type TSExcelFile = Class
|
||||
if err = 0 then
|
||||
begin
|
||||
workbook_ := new xlsxWorkBook(zipfile_);
|
||||
workbook_.Load();
|
||||
workbook_.Load();
|
||||
end
|
||||
return array(err, errmsg);
|
||||
End;
|
||||
@@ -78,7 +78,7 @@ Type TSExcelFile = Class
|
||||
if err = 0 then
|
||||
begin
|
||||
workbook_ := new xlsxWorkBook(zipfile_);
|
||||
workbook_.Load();
|
||||
workbook_.Load();
|
||||
end
|
||||
return array(err, errmsg);
|
||||
End;
|
||||
@@ -166,7 +166,7 @@ Type TSExcelFile = Class
|
||||
|
||||
///设置工作表名
|
||||
///sourceName: string, 原工作表名
|
||||
///destName: string,目标工作表名
|
||||
///destName: string, 目标工作表名
|
||||
Function SetSheetName(sourceName, destName);
|
||||
Begin
|
||||
return workbook_.SetSheetName(class(TSXml).CurCodePageToUtf8(sourceName), class(TSXml).CurCodePageToUtf8(destName));
|
||||
@@ -448,7 +448,7 @@ Type TSExcelFile = Class
|
||||
Function AddComment(sheet, axis, Author, comment);
|
||||
Begin
|
||||
o := getOj(sheet, 'xlsxComment');
|
||||
if ifObj(o) then o.AddComment(axis, Author, comment);
|
||||
if ifObj(o) then return o.AddComment(axis, Author, comment);
|
||||
End;
|
||||
|
||||
///获取批注
|
||||
@@ -457,13 +457,22 @@ Type TSExcelFile = Class
|
||||
///返回: [author:string, comment: string]
|
||||
Function GetComment(sheet, axis);
|
||||
Begin
|
||||
author := '';
|
||||
comment := '';
|
||||
author := nil;
|
||||
comment := nil;
|
||||
o := getOj(sheet, 'xlsxComment');
|
||||
if ifObj(o) then [author, comment] := o.GetComment(axis);
|
||||
return array(class(TSXml).Utf8ToCurCodePage(author), class(TSXml).Utf8ToCurCodePage(comment));
|
||||
End;
|
||||
|
||||
///移除批注
|
||||
///sheet: string,工作表名称
|
||||
///axis: string,单元格,如"A7"
|
||||
Function RemoveComment(sheet, axis);
|
||||
Begin
|
||||
o := getOj(sheet, 'xlsxComment');
|
||||
if ifObj(o) then return o.RemoveComment(axis);
|
||||
End;
|
||||
|
||||
///添加图表
|
||||
///sheet: string,工作表名称
|
||||
///range:string,图表所处矩形区域,"A5:F10"
|
||||
@@ -547,12 +556,22 @@ Type TSExcelFile = Class
|
||||
///新建样式对象
|
||||
///style: TStyle对象
|
||||
///返回: styleid
|
||||
Function NewStyle(style);
|
||||
Function NewStyle(style); overload;
|
||||
Begin
|
||||
styleObj := new xlsxStyles('', self);
|
||||
return styleObj.GetStyleId(style);
|
||||
End;
|
||||
|
||||
///新建样式对象,已存在样式的基础上返回新的样式Id
|
||||
///style: TStyle对象
|
||||
///oldStyleId: 已存在的styleId
|
||||
///返回: styleid
|
||||
Function NewStyle(style, oldStyleId); overload;
|
||||
Begin
|
||||
styleObj := new xlsxStyles('', self);
|
||||
return styleObj.GetStyleId(style, oldStyleId);
|
||||
End;
|
||||
|
||||
///获取样式对象
|
||||
///返回: TStyle对象
|
||||
Function GetStyle(styleid);
|
||||
@@ -1020,3 +1039,4 @@ private
|
||||
workbook_; //WorkBook对象
|
||||
objMgr_; //各种对象缓存、管理
|
||||
End;
|
||||
|
||||
|
||||
@@ -98,10 +98,7 @@ public
|
||||
arr := array('type': 'element', 'name': children_[i]['name'], 'attributes': array());
|
||||
if node_type = 'empty' then // <b/>
|
||||
begin
|
||||
end
|
||||
else if node_type = 'empty_string' then
|
||||
begin
|
||||
if ifstring(obj) then arr['attributes'] := array(key : obj);
|
||||
if obj = 0 then arr['attributes'] := array('val': 0);
|
||||
end
|
||||
else if node_type = 'pcdata' then
|
||||
begin
|
||||
@@ -175,7 +172,11 @@ public
|
||||
if istable(r) then Begin
|
||||
r := r[0];
|
||||
node := node.FirstChildElement(r['name']);
|
||||
if not ifObj(node) then return nil;
|
||||
if not ifObj(node) then
|
||||
begin
|
||||
if r['nodeType'] = 'empty' then return false;
|
||||
return nil;
|
||||
end
|
||||
if r['nodeType'] = 'empty' then
|
||||
return true;
|
||||
if r['nodeType'] = 'pcdata' then //返回文本串
|
||||
@@ -183,12 +184,6 @@ public
|
||||
if ifObj(r['obj']) then //对象,返回XML串
|
||||
return node.Data();
|
||||
key := r['attrName'] ? r['attrName'] : r['attrEx'] ? r['attrEx'] : 'val';
|
||||
if r['nodeType'] = 'empty_string' then
|
||||
begin
|
||||
val := node.GetAttribute(key);
|
||||
if not val then return true;
|
||||
return val;
|
||||
end
|
||||
return node.GetAttribute(key);//返回属性
|
||||
End;
|
||||
return nil;
|
||||
|
||||
@@ -154,10 +154,12 @@ xmlns:v="urn:schemas-microsoft-com:vml">
|
||||
|
||||
Function RemoveComment(cell);
|
||||
Begin
|
||||
node := commentObjs_(cell);
|
||||
node := commentObjs_[cell];
|
||||
if ifObj(node) then
|
||||
commentXmlFile_.FirstChildElement('comments').DeleteChild(node);
|
||||
return array(0, 'ok');
|
||||
begin
|
||||
commentXmlFile_.FirstChildElement('comments').FirstChildElement('commentList').DeleteChild(node);
|
||||
commentObjs_[cell] := nil;
|
||||
end
|
||||
End;
|
||||
|
||||
private
|
||||
|
||||
@@ -7,7 +7,7 @@ Type xlsxStyles = Class
|
||||
styleXmlFile_ := file_.WorkBook().GetXmlFileObj('xl/styles.xml');
|
||||
End
|
||||
|
||||
Function GetStyleId(style);
|
||||
Function GetStyleId(style);overload;
|
||||
Begin
|
||||
node := styleXmlFile_.FirstChildElement('styleSheet');
|
||||
font_id := insertNode(node, 'fonts', style.Font);
|
||||
@@ -45,6 +45,51 @@ Type xlsxStyles = Class
|
||||
return count;
|
||||
End;
|
||||
|
||||
Function GetStyleId(style, oldStyleId);overload;
|
||||
Begin
|
||||
if oldStyleId = '' then return nil;
|
||||
style_node := styleXmlFile_.FirstChildElement('styleSheet');
|
||||
cellXfs_node := style_node.FirstChildElement('cellXfs');
|
||||
count := strtoint(cellXfs_node.GetAttribute('count'));
|
||||
Id := strtoint(oldStyleId);
|
||||
if Id < count-1 then return nil;
|
||||
|
||||
xf := getNode(cellXfs_node, 'xf', Id);
|
||||
marshal := xf.marshal()[0];
|
||||
xf_node := cellXfs_node.InsertEndChild(marshal);
|
||||
cellXfs_node.SetAttribute('count', count + 1);
|
||||
attrs := marshal['attributes'];
|
||||
|
||||
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r : 0;
|
||||
copyNode(style_node, xf_node, 'numFmts', 'numFmt', 'numFmtId', numfmt_id, style.NumberFormat);
|
||||
|
||||
font_id := trystrtoint(attrs['fontId'], r) ? r : 0;
|
||||
copyNode(style_node, xf_node, 'fonts', 'font', 'fontId', font_id, style.Font);
|
||||
|
||||
border_id := trystrtoint(attrs['borderId'], r) ? r : 0;
|
||||
copyNode(style_node, xf_node, 'borders', 'border', 'borderId', border_id, style.Border);
|
||||
|
||||
fill_id := trystrtoint(attrs['fillId'], r) ? r : 0;
|
||||
copyNode(style_node, xf_node, 'fills', 'fill', 'fillId', fill_id, style.Fill);
|
||||
|
||||
marshal := style.Alignment.Marshal();
|
||||
alignment := xf_node.FirstChildElement('alignment');
|
||||
if ifObj(alignment) then class(TSXml).UpdateNode(alignment, marshal['attributes'], marshal['children']);
|
||||
else begin
|
||||
xf_node.InsertEndChild(marshal);
|
||||
xf_node.SetAttribute('applyAlignment', 1);
|
||||
end
|
||||
marshal := style.Protection.Marshal();
|
||||
protection := xf_node.FirstChildElement('protection');
|
||||
if ifObj(protection) then class(TSXml).UpdateNode(protection, marshal['attributes'], marshal['children']);
|
||||
else begin
|
||||
xf_node.InsertEndChild(marshal);
|
||||
xf_node.SetAttribute('applyProtection', 1);
|
||||
end
|
||||
|
||||
return inttostr(count);
|
||||
End;
|
||||
|
||||
Function GetStyle(styleId);
|
||||
Begin
|
||||
if styleId = '' then return nil;
|
||||
@@ -54,9 +99,9 @@ Type xlsxStyles = Class
|
||||
Id := strtoint(styleId);
|
||||
if Id < count-1 then return nil;
|
||||
|
||||
xf := getNode(style_node, 'cellXfs', 'xf', Id);
|
||||
xf := getNode(cellXfs_node, 'xf', Id);
|
||||
attrs := xf.Attributes();
|
||||
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r-1 : 0;
|
||||
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r : 0;
|
||||
font_id := trystrtoint(attrs['fontId'], r) ? r : 0;
|
||||
border_id := trystrtoint(attrs['borderId'], r) ? r : 0;
|
||||
fill_id := trystrtoint(attrs['fillId'], r) ? r : 0;
|
||||
@@ -64,10 +109,14 @@ Type xlsxStyles = Class
|
||||
alignment := xf.FirstChildElement('alignment');
|
||||
protection := xf.FirstChildElement('protection');
|
||||
style := TOfficeObj('TStyle');
|
||||
setRootObj(style.NumberFormat, getNode(style_node, 'numFmts', 'numFmt', numfmt_id));
|
||||
setRootObj(style.Font, getNode(style_node, 'fonts', 'font', font_id));
|
||||
setRootObj(style.Border, getNode(style_node, 'borders', 'border', border_id));
|
||||
node := getNode(style_node, 'fills', 'fill', fill_id);
|
||||
numFmts_node := style_node.FirstChildElement('numFmts');
|
||||
fonts_node := style_node.FirstChildElement('fonts');
|
||||
borders_node := style_node.FirstChildElement('borders');
|
||||
fills_node := style_node.FirstChildElement('fills');
|
||||
setRootObj(style.NumberFormat, getNode(numFmts_node, 'numFmt', numfmt_id));
|
||||
setRootObj(style.Font, getNode(fonts_node, 'font', font_id));
|
||||
setRootObj(style.Border, getNode(borders_node, 'border', border_id));
|
||||
node := getNode(fills_node, 'fill', fill_id);
|
||||
setRootObj(style.Fill, node);
|
||||
setFillGradientObj(style.Fill.Gradient, node);
|
||||
style.Alignment.RootObj := ifObj(alignment) ? alignment : nil;
|
||||
@@ -109,7 +158,7 @@ private
|
||||
obj.Stop3.NodeUri := '';
|
||||
end
|
||||
End;
|
||||
|
||||
|
||||
Function setRootObj(obj, node);
|
||||
Begin
|
||||
obj.RootObj := node;
|
||||
@@ -136,19 +185,62 @@ private
|
||||
end;
|
||||
End;
|
||||
|
||||
Function getNode(rootNode, nodeName, name, count);
|
||||
Function getNode(rootNode, name, count);
|
||||
Begin
|
||||
node := rootNode.FirstChildElement(nodeName);
|
||||
if not ifObj(node) then return nil;
|
||||
node := node.FirstChildElement(name);
|
||||
while count > 0 do
|
||||
if name = 'numFmt' then return getNodeNumFmts(rootNode, count);
|
||||
if not ifObj(rootNode) then return nil;
|
||||
node := rootNode.FirstChildElement(name);
|
||||
times := count;
|
||||
while times > 0 do
|
||||
begin
|
||||
node := node.NextElement();
|
||||
count--;
|
||||
times--;
|
||||
end
|
||||
return node;
|
||||
End;
|
||||
|
||||
Function getNodeNumFmts(rootNode, id);
|
||||
Begin
|
||||
if not ifObj(rootNode) then return nil;
|
||||
node := rootNode.FirstChildElement('numFmts');
|
||||
num_id := inttostr(id);
|
||||
while ifObj(node) do
|
||||
begin
|
||||
if num_id = node.GetAttribute('numFmtId') then return node;
|
||||
node := node.NextElement();
|
||||
end
|
||||
return nil;
|
||||
End;
|
||||
|
||||
Function copyNodeNumFmts(root, xf_node, id, obj);
|
||||
Begin
|
||||
nodeName_node := root.FirstChildElement('numFmts');
|
||||
if not ifObj(nodeName_node) then return;
|
||||
processNumFmtId(root, 'numFmts', obj.NumberFormat);
|
||||
new_node := nodeName_node.InsertEndChild(obj.Marshal());
|
||||
xf_node.SetAttribute('numFmtId', ifnil(obj.NumFmtId) ? 0 : obj.NumFmtId);
|
||||
count := nodeName_node.GetAttribute('count');
|
||||
nodeName_node.SetAttribute('count', strtoint(count) + 1);
|
||||
End;
|
||||
|
||||
Function copyNode(root, xf_node, nodeName, name, idName, id, obj);
|
||||
Begin
|
||||
if nodeName = 'numFmts' then return copyNodeNumFmts(root, xf_node, id, obj);
|
||||
nodeName_node := root.FirstChildElement(nodeName);
|
||||
if not ifObj(nodeName_node) then return;
|
||||
node := getNode(nodeName_node, name, id);
|
||||
new_node := nodeName_node.InsertEndChild(node.Marshal()[0]);
|
||||
count := strtoint(nodeName_node.GetAttribute('count'));
|
||||
nodeName_node.SetAttribute('count', count + 1);
|
||||
xf_node.SetAttribute(idName, count);
|
||||
|
||||
if ifObj(obj) then
|
||||
begin
|
||||
marshal := obj.Marshal();
|
||||
class(TSXml).UpdateNode(new_node, marshal['attributes'], marshal['children']);
|
||||
end;
|
||||
End;
|
||||
|
||||
Function insertNode(rootNode, childName, obj);
|
||||
Begin
|
||||
marshal := obj.Marshal();
|
||||
@@ -171,14 +263,11 @@ private
|
||||
Begin
|
||||
if ifnil(obj.FormatCode) or not ifnil(obj.numFmtId) then return;
|
||||
node := rootNode.FirstChildElement(childName);
|
||||
if not ifObj(node) then obj.numFmtId := '1';
|
||||
if not ifObj(node) then obj.numFmtId := '176';
|
||||
else begin
|
||||
node := node.LastChildElement('numFmt');
|
||||
if not ifObj(node) then obj.numFmtId := '1';
|
||||
else begin
|
||||
id := node.GetAttribute('numFmtId');
|
||||
obj.numFmtId := strtoint(id) + 1;
|
||||
end
|
||||
id := node.GetAttribute('numFmtId');
|
||||
obj.numFmtId := strtoint(id) + 1;
|
||||
end
|
||||
End
|
||||
|
||||
|
||||
Reference in New Issue
Block a user