v1.2.3
This commit is contained in:
parent
3d68bf2256
commit
7b0756e573
|
|
@ -227,13 +227,13 @@ Begin
|
|||
style.Font.UnderLine := 'singleAccounting';
|
||||
style.Fill.Gradient.Type := 'path';
|
||||
style.Fill.Gradient.Left := 0.5;
|
||||
style.Fill.Gradient.Right := 0.5;
|
||||
style.Fill.Gradient.Top := 0.5;
|
||||
style.Fill.Gradient.Bottom := 0.5;
|
||||
style.Fill.Gradient.Left := 0.5;
|
||||
style.Fill.Gradient.Left := 0.5;
|
||||
style.Fill.Gradient.Left := 0.5;
|
||||
style.Fill.Gradient.Stop1.Position := 0;
|
||||
style.Fill.Gradient.Stop1.Color := 'A3ECFB';
|
||||
style.Fill.Gradient.Stop1.Color := "A3ECFB";
|
||||
style.Fill.Gradient.Stop2.Position := 1;
|
||||
style.Fill.Gradient.Stop2.Color := '626AD8';
|
||||
style.Fill.Gradient.Stop2.Color := "626AD8";
|
||||
styleid1 := excel.NewStyle(style);
|
||||
|
||||
style := TOfficeObj('TStyle');
|
||||
|
|
@ -552,7 +552,7 @@ style.Protection.Lock := 1;
|
|||
('attrName': '', 'type': 'double', 'desc': '{颜色}:{Color}和{ThemeColor}只能设置一种', 'value': array()),
|
||||
('attrName': 'Color', 'type': 'string', 'desc': 'RGB颜色,如"A020F0"', 'value': array()),
|
||||
('attrName': 'ThemeColor', 'type': 'int', 'desc': '主题颜色', 'value': array()),
|
||||
('attrName': 'Underline', 'type': 'string', 'desc': '下划线', 'value': array('"double": 双下划线', '"singleAccounting": 会计单下划线', '"doubleAccounting": 会计双下划线')),
|
||||
('attrName': 'Underline', 'type': 'string', 'desc': '下划线', 'value': array('"none": 无', '"single": 单下划线', '"double": 双下划线', '"singleAccounting": 会计单下划线', '"doubleAccounting": 会计双下划线')),
|
||||
),
|
||||
'Demo': '',
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
TOfficeApi().CodePage('中文');
|
||||
TOfficeApi().CodePage('中文');
|
||||
|
||||
testCount := 0;
|
||||
sheetName := "你好";
|
||||
sheetName2 := "中文";
|
||||
sheetName := "你好";
|
||||
sheetName2 := "中文";
|
||||
|
||||
// OpenFile
|
||||
excel := new TSExcelFile();
|
||||
|
|
@ -43,14 +43,6 @@ println("[success] GetSheetName = {}", Name);
|
|||
excel.NewSheet(sheetName2);
|
||||
println("[success] NewSheet");
|
||||
|
||||
// NewSheet
|
||||
excel.NewSheet(sheetName, 'sheet_copy');
|
||||
println("[success] NewSheet2");
|
||||
|
||||
// InsertSheet
|
||||
excel.InsertSheet(sheetName, sheetName + 'before');
|
||||
println("[success] NewSheet2");
|
||||
|
||||
// GetSheets
|
||||
sheets := excel.GetSheets();
|
||||
println("[success] sheets = {}", sheets);
|
||||
|
|
@ -62,7 +54,7 @@ println("[success] DeleteSheet");
|
|||
|
||||
// SetCellValue
|
||||
excel.SetCellValue(sheetName, "A1", 100);
|
||||
excel.SetCellValue(sheetName, "F1", "中文的壹佰");
|
||||
excel.SetCellValue(sheetName, "F1", "中文的壹佰");
|
||||
println("[success] SetCellValue");
|
||||
|
||||
// GetCellValue
|
||||
|
|
@ -71,10 +63,6 @@ PrintInfo("GetCellValue A1 ", err, errmsg);
|
|||
[err, errmsg] := excel.GetCellValue(sheetName, "F1");
|
||||
PrintInfo("GetCellValue F1 ", err, errmsg);
|
||||
|
||||
// GetCellValue
|
||||
[err, errmsg] := excel.GetCellRawValue(sheetName, "A1");
|
||||
PrintInfo("GetCellRawValue A1 ", err, errmsg);
|
||||
|
||||
// TotalCols
|
||||
totalCols := excel.TotalCols(sheetName);
|
||||
println("[success] TotalCols = {}", totalCols);
|
||||
|
|
@ -85,7 +73,7 @@ println("[success] TotalRows = {}", totalRows);
|
|||
|
||||
// SetCellRichText
|
||||
richText := TOfficeObj('TRichtext');
|
||||
text1 := richText.AddText('Hello 你好');
|
||||
text1 := richText.AddText('Hello 你好');
|
||||
text1.Font.Size := 35;
|
||||
text1.Font.Color := "FFF000";
|
||||
text2 := richText.AddText(" World");
|
||||
|
|
@ -105,7 +93,7 @@ excel.ClearCell(sheetName, "A1");
|
|||
println("[success] ClearCell");
|
||||
|
||||
// SetCellFormula
|
||||
excel.SetCellFormula(sheetName, "A2", "100*50");
|
||||
excel.SetCellFormula(sheetName, "A2", "=100*50");
|
||||
println("[success] SetCellFormula");
|
||||
|
||||
// GetCellFormula
|
||||
|
|
@ -117,7 +105,7 @@ excel.SetSheetRow(sheetName, "C3", array(1, 2, 3, 4, "a", "b"));
|
|||
println("[success] SetSheetRow");
|
||||
|
||||
// InsertTable
|
||||
table := array((1, 2, "你好"), (4, 5, "b"));
|
||||
table := array((1, 2, "你好"), (4, 5, "b"));
|
||||
//table2 := array(("title1" :1, "title2": 2), ("title1": 3, "title2": 4));
|
||||
[err, errmsg] := excel.InsertTable(sheetName, "A5", table);
|
||||
PrintInfo("InsertTable", err, errmsg);
|
||||
|
|
@ -231,12 +219,6 @@ PrintInfo("ColumnNumberToName", err, errmsg);
|
|||
[err, col, row] := excel.CellNameToCoordinates("A2");
|
||||
if not err then println("[success] {} = col : {}, row = {}", "CellNameToCoordinates", col, row);
|
||||
|
||||
// CoordinatesToCellName
|
||||
[err, cell] := excel.CoordinatesToCellName(1, 2, true);
|
||||
println("[success] CoordinatesToCellName, cell = {}", cell);
|
||||
[err, cell] := excel.CoordinatesToCellName(1, 2);
|
||||
println("[success] CoordinatesToCellName, cell = {}", cell);
|
||||
|
||||
// RGBToHSL
|
||||
[h, s, l] := excel.RGBToHSL(255, 15, 33);
|
||||
println("[success] {} = {}, {}, {}", "RGBToHSL", h, s, l);
|
||||
|
|
@ -249,7 +231,7 @@ println("[success] {} = {}, {}, {}", "HSLToRGB", r, g, b);
|
|||
style := TOfficeObj('TStyle');
|
||||
style.Font.Color := "A020F0";
|
||||
style.Font.Size := 22;
|
||||
style.Font.Name := "黑体";
|
||||
style.Font.Name := "黑体";
|
||||
style.Font.Bold := True;
|
||||
style.Font.Charset := "134";
|
||||
style.Font.Script := "subscript";
|
||||
|
|
@ -277,11 +259,9 @@ style.NumberFormat.FormatCode := "#,##0.000_ ";
|
|||
//style.Fill.Pattern.PatternType := "solid";
|
||||
//style.Fill.Pattern.ForegroundColor := "FF6699FF";
|
||||
//style.Fill.Pattern.BackgroundColor := "FFFF0000";
|
||||
style.Fill.Gradient.Degree := 270;
|
||||
style.Fill.Gradient.Stop1.Position := 0;
|
||||
style.Fill.Gradient.Stop1.ThemeColor := 0;
|
||||
style.Fill.Gradient.Stop2.Position := 1;
|
||||
style.Fill.Gradient.Stop2.ThemeColor := 4;
|
||||
style.Fill.Gradient.ThemeColor1 := 0;
|
||||
style.Fill.Gradient.ThemeColor2 := 4;
|
||||
style.Fill.Gradient.Shading := 1;
|
||||
style.Protection.Hide := 1;
|
||||
style.Protection.Lock := 1;
|
||||
|
||||
|
|
@ -297,31 +277,6 @@ println("[success] GetCellStyle = {}", styleid);
|
|||
styleid := excel.GetCellStyle(sheetName, "D4");
|
||||
println("[success] GetCellStyle = {}", styleid);
|
||||
|
||||
style := excel.GetStyle(styleid);
|
||||
println("font.Name = {}", style.Font.Name);
|
||||
println("font.Italic = {}", style.Font.Italic);
|
||||
println("border.left.Color = {}", style.border.left.Color);
|
||||
println("border.Top.LineStyle = {}", style.border.Top.LineStyle);
|
||||
println("border.DiagonalDown = {}", style.border.DiagonalDown);
|
||||
println("numberFormat.FormatCode = {}", style.NumberFormat.FormatCode);
|
||||
println("alignment.vertical = {}", style.Alignment.Vertical);
|
||||
println("alignment.TextRotation = {}", style.Alignment.TextRotation);
|
||||
println("protection.Hide = {}", style.Protection.Hide);
|
||||
println("protection.Lock = {}", style.Protection.Lock);
|
||||
//println("fill.pattern.PatternType = {}", style.Fill.Pattern.PatternType);
|
||||
//println("fill.pattern.ForegroundColor = {}", style.Fill.Pattern.ForegroundColor);
|
||||
println("style.Fill.Gradient.Degree = {}", style.Fill.Gradient.Degree);
|
||||
println("style.Fill.Gradient.Stop1.ThemeColor = {}", style.Fill.Gradient.Stop1.ThemeColor);
|
||||
println("style.Fill.Gradient.Stop2.Position = {}", style.Fill.Gradient.Stop2.Position);
|
||||
|
||||
style.Protection.Hide := 0;
|
||||
style.Protection.Lock := 0;
|
||||
style.Apply();
|
||||
style := excel.GetStyle(styleid);
|
||||
|
||||
println("protection.Hide = {}", style.Protection.Hide);
|
||||
println("protection.Lock = {}", style.Protection.Lock);
|
||||
|
||||
// SetSheetHeaderFooter
|
||||
headerFooter := TOfficeObj("THeaderFooter");
|
||||
headerFooter.DifferentOddEven := true;
|
||||
|
|
@ -377,8 +332,8 @@ println("[success] SetPageMargins");
|
|||
// GetPageMargins
|
||||
margins := excel.GetPageMargins(sheetName2);
|
||||
println("[success] GetPageMargins top = {}, bottom = {}, left = {}, right = {}, header = {}, footer = {}",
|
||||
margins.Top, margins.Bottom, margins.Left, margins.Right,
|
||||
margins.Header, margins.Footer);
|
||||
margins.Value('Top'), margins.Value('Bottom'), margins.Value('Left'), margins.Value('Right'),
|
||||
margins.Value('Header'), margins.Value('Footer'));
|
||||
|
||||
// MergeCell
|
||||
excel.SetCellStyle(sheetName2, "A4", "A4", styleid1);
|
||||
|
|
@ -417,7 +372,6 @@ println("[success] SetPane");
|
|||
pageLayout := TOfficeObj('TPageLayout');
|
||||
pageLayout.FitToWidth := 10;
|
||||
pageLayout.FitToHeight := 10;
|
||||
pageLayout.UseFirstPageNumber := true;
|
||||
pageLayout.FirstPageNumber := 5;
|
||||
pageLayout.Orientation := "portrait";
|
||||
pageLayout.BlackAndWhite := true;
|
||||
|
|
@ -448,8 +402,8 @@ excel.SetCellHyperLink(sheetName2, 'A1', link);
|
|||
link := TOfficeObj('THyperLink');
|
||||
link.LinkType := "external";
|
||||
link.LinkUrl := "https://www.baidu.com";
|
||||
link.Tooltip := "超链接悬浮提示";
|
||||
excel.SetCellValue(sheetName2, 'A2', '超链接');
|
||||
link.Tooltip := "超链接悬浮提示";
|
||||
excel.SetCellValue(sheetName2, 'A2', '超链接');
|
||||
excel.SetCellHyperLink(sheetName2, 'A2', link);
|
||||
println("[success] SetCellHyperLink");
|
||||
|
||||
|
|
@ -477,12 +431,12 @@ println("[success] AddPicture");
|
|||
excel.DeletePicture(sheetName2, 'A1', 'D17');
|
||||
println("[success] DeletePicture");
|
||||
|
||||
// TODO 可能有问题
|
||||
// TODO 可能有问题
|
||||
// AddTable
|
||||
table2 := array(("title1" :1, "title2": 2), ("title1": 3, "title2": 4));
|
||||
excel.InsertTable(sheetName2, "A9", table2, true);
|
||||
tablestyle := TOfficeObj('TTableStyle');
|
||||
tablestyle.TableName := "测试表";
|
||||
tablestyle.TableName := "测试表";
|
||||
tablestyle.TableStyle := "TableStyleMedium2";
|
||||
tablestyle.ShowFirstColumn := True;
|
||||
tablestyle.ShowLastColumn := True;
|
||||
|
|
@ -512,9 +466,9 @@ println("[success] AddShape");
|
|||
|
||||
// SetCoreProps
|
||||
core := TOfficeObj('TCoreProperty');
|
||||
core.Title := "标题";
|
||||
core.Subject := "主题";
|
||||
core.Creator := "作者";
|
||||
core.Title := "标题";
|
||||
core.Subject := "主题";
|
||||
core.Creator := "作者";
|
||||
excel.SetCoreProps(core);
|
||||
|
||||
// GetCoreProps
|
||||
|
|
@ -530,8 +484,8 @@ appProps.Company := "TS";
|
|||
appProps.LinksUpToDate := "true";
|
||||
appProps.HyperlinksChanged := "true";
|
||||
appProps.Version := "1.000";
|
||||
appProps.Manager := "这是主管";
|
||||
//appProps.HyperlinkBase := "这是超链接基础";
|
||||
appProps.Manager := "这是主管";
|
||||
//appProps.HyperlinkBase := "这是超链接基础";
|
||||
excel.SetAppProps(appProps);
|
||||
println("[success] SetAppProps");
|
||||
|
||||
|
|
@ -565,7 +519,7 @@ println("[success] ProtectSheet");
|
|||
|
||||
// SetDefaultFont
|
||||
font := tofficeobj('tfont');
|
||||
font.Name := '黑体';
|
||||
font.Name := '黑体';
|
||||
font.Size := 13;
|
||||
font.ThemeColor := 1;
|
||||
excel.SetDefaultFont(font);
|
||||
|
|
@ -574,44 +528,6 @@ println("[success] SetDefaultFont");
|
|||
tfont := excel.GetDefaultFont();
|
||||
println("[success] GetDefaultFont , name = {}, size = {}, themecolor = {}", tfont.Name, tfont.Size, tfont.ThemeColor);
|
||||
|
||||
calcpr := TOfficeObj('TCalcPr');
|
||||
calcpr.CalcMode := "";
|
||||
calcpr.RefMode := "R1C1";
|
||||
calcpr.Iterate := 1;
|
||||
calcpr.IterateCount := 300;
|
||||
calcpr.IterateDelta := "3E-3";
|
||||
calcpr.CalcOnSave := true;
|
||||
calcpr.ConCurrentCalc := true;
|
||||
calcpr.ConCurrentManualCount := 4;
|
||||
calcpr.FullPrecision := 0;
|
||||
excel.SetCalcOptions(calcpr);
|
||||
println("[success] SetCalcOptions");
|
||||
|
||||
calc := excel.GetCalcOptions();
|
||||
println("[success] GetCalcOptions, CalcMode = {}, RefMode = {}, Iterate = {},
|
||||
IterateCount = {}, IterateDelta = {}, CalcOnSave = {}, conCurrentCalc = {},
|
||||
conCurrentManualCount = {}, FullPrecision = {}", calc.CalcMode, calc.RefMode, calc.Iterate,
|
||||
calc.IterateCount, calc.IterateDelta, calc.CalcOnSave, calc.conCurrentCalc,
|
||||
calc.conCurrentManualCount, calc.FullPrecision);
|
||||
|
||||
excel.SetRowOutlineLevel(sheetName2, 1, 1);
|
||||
excel.SetRowOutlineLevel(sheetName2, 2, 1);
|
||||
println("[success] SetRowOutlineLevel");
|
||||
|
||||
level1 := excel.GetRowOutlineLevel(sheetName2, 1);
|
||||
level2 := excel.GetRowOutlineLevel(sheetName2, 3);
|
||||
|
||||
println("[success] GetRowOutlineLevel, level1 = {}, level2 = {}", level1, level2);
|
||||
|
||||
excel.SetColOutlineLevel(sheetName2, 'A', 1);
|
||||
excel.SetColOutlineLevel(sheetName2, 'B', 2);
|
||||
excel.SetColOutlineLevel(sheetName2, 'C', 1);
|
||||
println("[success] SetColOutlineLevel");
|
||||
|
||||
level1 := excel.GetColOutlineLevel(sheetName2, 'A');
|
||||
level2 := excel.GetColOutlineLevel(sheetName2, 'B');
|
||||
println("[success] GetColOutlineLevel, level1 = {}, level2 = {}", level1, level2);
|
||||
|
||||
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
|
||||
println("saveas : {}", err);
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
|
|
@ -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,15 +263,12 @@ 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
|
||||
end
|
||||
End
|
||||
|
||||
private
|
||||
|
|
|
|||
Loading…
Reference in New Issue