This commit is contained in:
csh 2023-03-20 10:18:15 +08:00
parent fbec04c5e7
commit 84673ea219
8 changed files with 50 additions and 35 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
// Version 1.2.4
// Version 1.2.5
Function TOfficeObj(n);
Begin
@ -3755,19 +3755,6 @@ type TNumFmts=class(NodeInfo)
RootObj := node;
End;
Property NumFmtId read readXMLNumFmtId write writeXMLNumFmtId;
Function readXMLNumFmtId();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('NumFmtId'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLNumFmtId);
End;
Function writeXMLNumFmtId(str);
Begin
XMLNumFmtId := class(TSXml).CurCodePageToUtf8(str);
End;
Property FormatCode read readXMLFormatCode write writeXMLFormatCode;
Function readXMLFormatCode();
Begin
@ -3784,7 +3771,7 @@ type TNumFmts=class(NodeInfo)
Function GetAttrs(); override;
Begin
HandleAttrs();
return array(("NumFmtId", "numFmtId", XMLNumFmtId, ""),("FormatCode", "formatCode", XMLFormatCode, "")) union ExtAttr;
return array(("NumFmtId", "numFmtId", NumFmtId, ""),("FormatCode", "formatCode", XMLFormatCode, "")) union ExtAttr;
End;
Function GetChildren(); override;
@ -3794,7 +3781,7 @@ type TNumFmts=class(NodeInfo)
End;
//Attributes
XMLNumFmtId;
NumFmtId;
XMLFormatCode;
//Nodes

View File

@ -1,4 +1,4 @@
// Version 1.2.4
// Version 1.2.5
Type TSDocxFile = Class
///Version: V1.0 2022-09-20

View File

@ -1,4 +1,4 @@
// Version 1.2.4
// Version 1.2.5
Type TSExcelFile = Class
///Version: V1.0 2022-08-08

View File

@ -137,7 +137,7 @@ xmlns:v="urn:schemas-microsoft-com:vml">
Function GetComment(cell);
Begin
o := commentObjs_[cell];
if not ifObj(o) then return array('', '');
if not ifObj(o) then return array(nil, nil);
r_node := o.FirstChildElement('text').FirstChildElement('r');
author := r_node.FirstChildElement('t').GetText();
if length(author) > 1 then author := author[:length(author)-1];

View File

@ -45,7 +45,7 @@ Type xlsxStyles = Class
return count;
End;
Function GetStyleId(style, oldStyleId);overload;
Function GetStyleId(newStyle, oldStyleId);overload;
Begin
if oldStyleId = '' then return nil;
style_node := styleXmlFile_.FirstChildElement('styleSheet');
@ -60,6 +60,8 @@ Type xlsxStyles = Class
cellXfs_node.SetAttribute('count', count + 1);
attrs := marshal['attributes'];
style := newStyle;
numfmt_id := trystrtoint(attrs['numFmtId'], r) ? r : 0;
copyNode(style_node, xf_node, 'numFmts', 'numFmt', 'numFmtId', numfmt_id, style.NumberFormat);
@ -214,13 +216,27 @@ private
Function copyNodeNumFmts(root, xf_node, id, obj);
Begin
if id = 0 then
begin
if ifnil(obj.FormatCode) then xf_node.SetAttribute('numFmtId', 0);
else begin
obj.NumFmtId := 176;
insertNode(root, 'numFmts', obj);
xf_node.SetAttribute('numFmtId', 176);
end
end
else 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);
println("id = {}", id);
num_node := getNodeNumFmts(nodeName_node, id);
processNumFmtId(root, 'numFmts', obj);
new_node := nodeName_node.InsertEndChild(num_node.Marshal()[0]);
count := strtoint(nodeName_node.GetAttribute('count'));
nodeName_node.SetAttribute('count', count + 1);
xf_node.SetAttribute('numFmtId', obj.NumFmtId);
marshal := obj.Marshal();
class(TSXml).UpdateNode(new_node, marshal['attributes'], marshal['children']);
end
End;
Function copyNode(root, xf_node, nodeName, name, idName, id, obj);
@ -255,20 +271,19 @@ private
count := node.GetAttribute('count');
node.InsertEndChild(marshal);
node.SetAttribute('count', strtoint(count) + 1);
//node.Print;
return count;
End
Function processNumFmtId(rootNode, childName, obj);
Begin
if ifnil(obj.FormatCode) or not ifnil(obj.numFmtId) then return;
if ifnil(obj.FormatCode) then return;
node := rootNode.FirstChildElement(childName);
if not ifObj(node) then obj.numFmtId := '176';
if not ifObj(node) then id := 176;
else begin
node := node.LastChildElement('numFmt');
id := node.GetAttribute('numFmtId');
obj.numFmtId := strtoint(id) + 1;
id := strtoint(node.GetAttribute('numFmtId')) + 1;
end
obj.numFmtId := id;
End
private

View File

@ -865,8 +865,10 @@ Type xlsxWorkBook = Class
return strtofloat(default_ht);
End
Function SetColWidth(sheet, startCol, endCol, width);
Function SetColWidth(sheet, bCol, eCol, width);
Begin
startCol := bCol;
endCol := eCol;
startCol := ColumnNameToNumber(startCol)[1];
endCol := ColumnNameToNumber(endCol)[1];
if startCol > endCol then return;
@ -915,13 +917,13 @@ Type xlsxWorkBook = Class
default_width := trystrtofloat(default_width, r) ? r: -1;
if not ifObj(col_node) then return array(0, default_width);
col := ColumnNameToNumber(col)[1];
col_number := ColumnNameToNumber(col)[1];
node := col_node.FirstChildElement('col');
while ifObj(node) do
Begin
min := strtoint(node.GetAttribute('min'));
max := strtoint(node.GetAttribute('max'));
if col >= min and col <= max then
if col_number >= min and col_number <= max then
Begin
width := trystrtofloat(node.GetAttribute('width'), r) ? r : -1;
if width = -1 then break;

View File

@ -1,5 +1,16 @@
# 更新日志
## 2023-3-20
### V1.2.5
#### excel
1. 修复数字样式获取再赋值再获取失效问题
2. 支持单元格填入`nil`
3. `GetComment`获取不到批注时返回内容改为`array(nil,nil)`
4. 修复`Set/GetColWitdh`传入变量时会被修改问题
## 2023-3-16
### V1.2.4