v1.0.6
This commit is contained in:
parent
9b8b7f79d9
commit
a4ff2eae83
|
|
@ -1,4 +1,4 @@
|
||||||
class(xlsxXml).CodePage('中文');
|
TOfficeApi().CodePage('中文');
|
||||||
|
|
||||||
testCount := 0;
|
testCount := 0;
|
||||||
sheetName := "你好";
|
sheetName := "你好";
|
||||||
|
|
@ -207,10 +207,6 @@ End;
|
||||||
[err, col, row] := excel.SplitCellName("AK47");
|
[err, col, row] := excel.SplitCellName("AK47");
|
||||||
if not err then println("[success] {} = col : {}, row = {}", "SplitCellName", col, row);
|
if not err then println("[success] {} = col : {}, row = {}", "SplitCellName", col, row);
|
||||||
|
|
||||||
// JoinCellName
|
|
||||||
[err, errmsg] := excel.JoinCellName("AK", 47);
|
|
||||||
PrintInfo("JoinCellName", err, errmsg);
|
|
||||||
|
|
||||||
// ColumnNameToNumber
|
// ColumnNameToNumber
|
||||||
[err, errmsg] := excel.ColumnNameToNumber("AK");
|
[err, errmsg] := excel.ColumnNameToNumber("AK");
|
||||||
PrintInfo("ColumnNameToNumber", err, errmsg);
|
PrintInfo("ColumnNameToNumber", err, errmsg);
|
||||||
|
|
@ -224,12 +220,12 @@ PrintInfo("ColumnNumberToName", err, errmsg);
|
||||||
if not err then println("[success] {} = col : {}, row = {}", "CellNameToCoordinates", col, row);
|
if not err then println("[success] {} = col : {}, row = {}", "CellNameToCoordinates", col, row);
|
||||||
|
|
||||||
// RGBToHSL
|
// RGBToHSL
|
||||||
[err, h, s, l] := excel.RGBToHSL(255, 15, 33);
|
[h, s, l] := excel.RGBToHSL(255, 15, 33);
|
||||||
if not err then println("[success] {} = {}, {}, {}", "RGBToHSL", h, s, l);
|
println("[success] {} = {}, {}, {}", "RGBToHSL", h, s, l);
|
||||||
|
|
||||||
// HSLToRGB
|
// HSLToRGB
|
||||||
[err, r, g, b] := excel.HSLToRGB(h, s, l);
|
[r, g, b] := excel.HSLToRGB(h, s, l);
|
||||||
if not err then println("[success] {} = {}, {}, {}", "HSLToRGB", h, s, l);
|
println("[success] {} = {}, {}, {}", "HSLToRGB", r, g, b);
|
||||||
|
|
||||||
// NewStyle
|
// NewStyle
|
||||||
style := TOfficeObj('TStyle');
|
style := TOfficeObj('TStyle');
|
||||||
|
|
@ -380,11 +376,11 @@ println("[success] GetDefaultSheet = {}", sheet);
|
||||||
|
|
||||||
// SetCellHyperLink
|
// SetCellHyperLink
|
||||||
link := TOfficeObj('THyperLink');
|
link := TOfficeObj('THyperLink');
|
||||||
link.LinkType := "Location";
|
link.LinkType := "location";
|
||||||
link.LinkUrl := sheetName $ "!A1";
|
link.LinkUrl := sheetName $ "!A1";
|
||||||
excel.SetCellHyperLink(sheetName2, 'A1', link);
|
excel.SetCellHyperLink(sheetName2, 'A1', link);
|
||||||
link := TOfficeObj('THyperLink');
|
link := TOfficeObj('THyperLink');
|
||||||
link.LinkType := "External";
|
link.LinkType := "external";
|
||||||
link.LinkUrl := "https://www.baidu.com";
|
link.LinkUrl := "https://www.baidu.com";
|
||||||
link.Tooltip := "超链接悬浮提示";
|
link.Tooltip := "超链接悬浮提示";
|
||||||
excel.SetCellValue(sheetName2, 'A2', '超链接');
|
excel.SetCellValue(sheetName2, 'A2', '超链接');
|
||||||
|
|
@ -393,7 +389,7 @@ println("[success] SetCellHyperLink");
|
||||||
|
|
||||||
// GetCellHyperLink
|
// GetCellHyperLink
|
||||||
hyperlink := excel.GetCellHyperLink(sheetName2, 'A2');
|
hyperlink := excel.GetCellHyperLink(sheetName2, 'A2');
|
||||||
println("[success] GetCellHyperLink LinkType = {}, LinkUrl = {}, Tooltip = {}", hyperlink.Value('LinkType'), hyperlink.Value('LinkUrl'), hyperlink.Value('Tooltip'));
|
println("[success] GetCellHyperLink LinkType = {}, LinkUrl = {}, Tooltip = {}", hyperlink.LinkType, hyperlink.LinkUrl, hyperlink.Tooltip);
|
||||||
|
|
||||||
// SetSheetBackground
|
// SetSheetBackground
|
||||||
ret := readfile(rwBinary(), "", "C:\\Users\\csh05\\Pictures\\Saved Pictures\\1.jpg", 0, 1024000, data);
|
ret := readfile(rwBinary(), "", "C:\\Users\\csh05\\Pictures\\Saved Pictures\\1.jpg", 0, 1024000, data);
|
||||||
|
|
@ -454,11 +450,10 @@ core.Title := "标题";
|
||||||
core.Subject := "主题";
|
core.Subject := "主题";
|
||||||
core.Creator := "作者";
|
core.Creator := "作者";
|
||||||
excel.SetCoreProps(core);
|
excel.SetCoreProps(core);
|
||||||
println("[success] SetCoreProps");
|
|
||||||
|
|
||||||
// GetCoreProps
|
// GetCoreProps
|
||||||
core := excel.GetCoreProps();
|
core := excel.GetCoreProps();
|
||||||
println("[success] GetCoreProps Title = {}, subject = {}, Creator = {}", core.Value("Title"), core.Value("Subject"), core.Value("Creator"));
|
println("[success] GetCoreProps Title = {}, subject = {}, Creator = {}", core.Title, core.Subject, core.Creator);
|
||||||
|
|
||||||
// SetAppProps
|
// SetAppProps
|
||||||
appProps := TOfficeObj('TAppProperty');
|
appProps := TOfficeObj('TAppProperty');
|
||||||
|
|
@ -476,7 +471,7 @@ println("[success] SetAppProps");
|
||||||
|
|
||||||
// GetAppProps
|
// GetAppProps
|
||||||
app_props := excel.GetAppProps();
|
app_props := excel.GetAppProps();
|
||||||
println("[success] GetAppProps Manager = {}, Company = {}, Application = {}", app_props.Value('Manager'), app_props.Value('Company'), app_props.Value('Application'));
|
println("[success] GetAppProps Manager = {}, Company = {}, Application = {}", app_props.Manager, app_props.Company, app_props.Application);
|
||||||
|
|
||||||
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
|
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
|
||||||
println("saveas : {}", err);
|
println("saveas : {}", err);
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,9 @@ _13_TNumbering(docx);
|
||||||
///TDocxChart
|
///TDocxChart
|
||||||
_14_TDocxChart(docx);
|
_14_TDocxChart(docx);
|
||||||
|
|
||||||
|
///TOfficeApi
|
||||||
|
_15_TOfficeApi(docx);
|
||||||
|
|
||||||
///附注
|
///附注
|
||||||
_Annotation(docx);
|
_Annotation(docx);
|
||||||
|
|
||||||
|
|
@ -790,6 +793,20 @@ Begin
|
||||||
println(' >>OK\n');
|
println(' >>OK\n');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
///TOfficeApi
|
||||||
|
Function _15_TOfficeApi(docx);
|
||||||
|
Begin
|
||||||
|
paragraph := sysparams['Test'];
|
||||||
|
_PrintMsg('TOfficeApi接口');
|
||||||
|
_AddTitle(docx, 'TOfficeApi', 1);
|
||||||
|
|
||||||
|
_AddTitle(docx, 'TOfficeApi接口', 2);
|
||||||
|
conf := _LoadClassInfo(docx.GetPath() + '\\funcext\\TSOffice\\TSUtils\\TOffice.tsf', 'TOffice');
|
||||||
|
_AddFunctionHelpInfo(docx, '' $ paragraph $ '.1.', conf, 3);
|
||||||
|
|
||||||
|
println(' >>OK\n');
|
||||||
|
End;
|
||||||
|
|
||||||
Function _AddTitle(docx, subject, level);
|
Function _AddTitle(docx, subject, level);
|
||||||
Begin
|
Begin
|
||||||
leftIndent := array((0,0), (425,425), (453,850), (708,1508));
|
leftIndent := array((0,0), (425,425), (453,850), (708,1508));
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -1,4 +1,4 @@
|
||||||
// Version 1.0.5
|
// Version 1.0.6
|
||||||
|
|
||||||
Type TSDocxFile = Class
|
Type TSDocxFile = Class
|
||||||
///Version: V1.0 2022-09-20
|
///Version: V1.0 2022-09-20
|
||||||
|
|
@ -27,8 +27,9 @@ Type TSDocxFile = Class
|
||||||
|
|
||||||
Function init();
|
Function init();
|
||||||
Begin
|
Begin
|
||||||
|
DocPrId_ := -1;
|
||||||
zipfile_ := new ZipFile();
|
zipfile_ := new ZipFile();
|
||||||
xml_ := new xlsxXml();
|
xml_ := new TSXml();
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///打开docx文件
|
///打开docx文件
|
||||||
|
|
@ -94,7 +95,7 @@ Type TSDocxFile = Class
|
||||||
///返回TParagraph对象
|
///返回TParagraph对象
|
||||||
Function AddParagraph(paragraph, posOpt, styleId);
|
Function AddParagraph(paragraph, posOpt, styleId);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddParagraph(paragraph, posOpt, styleId);
|
return document_.Body().AddParagraph(paragraph, getPosNode(posOpt), styleId);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加标题
|
///添加标题
|
||||||
|
|
@ -108,7 +109,7 @@ Type TSDocxFile = Class
|
||||||
style := StyleObject().GetStyle(styleName);
|
style := StyleObject().GetStyle(styleName);
|
||||||
if not ifObj(style) and ifInt(level) and level >= 0 and level <= 9 then
|
if not ifObj(style) and ifInt(level) and level >= 0 and level <= 9 then
|
||||||
style := StyleObject().AddDefaultStyle(GetPath(), styleName);
|
style := StyleObject().AddDefaultStyle(GetPath(), styleName);
|
||||||
return document_.Body().AddHeading(title, posOpt, ifObj(style) ? style.StyleId : nil);
|
return document_.Body().AddHeading(title, getPosNode(posOpt), ifObj(style) ? style.StyleId : nil);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入分页符
|
///插入分页符
|
||||||
|
|
@ -116,7 +117,7 @@ Type TSDocxFile = Class
|
||||||
///返回TParagraph对象
|
///返回TParagraph对象
|
||||||
Function AddPageBreak(posOpt);
|
Function AddPageBreak(posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddBreak(posOpt, 'page');
|
return document_.Body().AddBreak(getPosNode(posOpt), 'page');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入换行符
|
///插入换行符
|
||||||
|
|
@ -124,7 +125,7 @@ Type TSDocxFile = Class
|
||||||
///返回TParagraph对象
|
///返回TParagraph对象
|
||||||
Function AddLineBreak(posOpt);
|
Function AddLineBreak(posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddBreak(posOpt, '');
|
return document_.Body().AddBreak(getPosNode(posOpt), '');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入分栏符
|
///插入分栏符
|
||||||
|
|
@ -132,7 +133,7 @@ Type TSDocxFile = Class
|
||||||
///返回TParagraph对象
|
///返回TParagraph对象
|
||||||
Function AddColumnBreak(posOpt);
|
Function AddColumnBreak(posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddBreak(posOpt, 'column');
|
return document_.Body().AddBreak(getPosNode(posOpt), 'column');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///删除指定段落
|
///删除指定段落
|
||||||
|
|
@ -140,7 +141,7 @@ Type TSDocxFile = Class
|
||||||
///返回:true
|
///返回:true
|
||||||
Function DelParagraph(posOpt);
|
Function DelParagraph(posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().DelParagraph(posOpt);
|
return document_.Body().DelParagraph(getPosNode(posOpt));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///word文档所有内容的文本串
|
///word文档所有内容的文本串
|
||||||
|
|
@ -150,8 +151,8 @@ Type TSDocxFile = Class
|
||||||
return document_.Body().Text();
|
return document_.Body().Text();
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///word文档所有内容的文本串数组,包含段落信息
|
//word文档所有内容的文本串数组,包含段落信息
|
||||||
///返回:array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r))
|
//返回:array(("pNode":nodeObj, "pIndex":p, "rNode":nodeObj, "rIndex":r))
|
||||||
Function TextArray();
|
Function TextArray();
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().TextArray();
|
return document_.Body().TextArray();
|
||||||
|
|
@ -193,7 +194,7 @@ Type TSDocxFile = Class
|
||||||
///返回: TTable对象
|
///返回: TTable对象
|
||||||
Function InsertTable(tbl, posOpt);
|
Function InsertTable(tbl, posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().InsertTable(tbl, posOpt);
|
return document_.Body().InsertTable(tbl, getPosNode(posOpt));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///返回CoreProperties对象
|
///返回CoreProperties对象
|
||||||
|
|
@ -225,7 +226,7 @@ Type TSDocxFile = Class
|
||||||
///返回:TDocSection对象
|
///返回:TDocSection对象
|
||||||
Function AddSection(session, posOpt);overload;
|
Function AddSection(session, posOpt);overload;
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddSection(session, posOpt);
|
return document_.Body().AddSection(session, getPosNode(posOpt));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入图片
|
///插入图片
|
||||||
|
|
@ -234,7 +235,8 @@ Type TSDocxFile = Class
|
||||||
///返回:TPicture对象
|
///返回:TPicture对象
|
||||||
Function AddPicture(picture, posOpt);
|
Function AddPicture(picture, posOpt);
|
||||||
Begin
|
Begin
|
||||||
return document_.Body().AddPicture(picture, posOpt);
|
picture.Run.Drawing.WInline.ID := GetDocPrId();
|
||||||
|
return document_.Body().AddPicture(picture, getPosNode(posOpt));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入图表
|
///插入图表
|
||||||
|
|
@ -246,9 +248,9 @@ Type TSDocxFile = Class
|
||||||
o := new TDocxChart(self, chart);
|
o := new TDocxChart(self, chart);
|
||||||
p := TOfficeObj('TParagraph');
|
p := TOfficeObj('TParagraph');
|
||||||
p.Format.rPr.Lang := 'zh-CN';
|
p.Format.rPr.Lang := 'zh-CN';
|
||||||
p := AddParagraph(p, posOpt, nil);
|
p := AddParagraph(p, getPosNode(posOpt), nil);
|
||||||
chart.ChartNode := p.node_;
|
chart.pNode := p.node_;
|
||||||
p.Node.InsertEndChild(o.GetInnerXml());
|
p.Node().InsertEndChild(o.GetInnerXml());
|
||||||
return chart;
|
return chart;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -260,7 +262,7 @@ Type TSDocxFile = Class
|
||||||
uri := 'w:p/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart';
|
uri := 'w:p/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart';
|
||||||
ps := Paragraphs();
|
ps := Paragraphs();
|
||||||
for i:=0 to length(ps)-1 do Begin
|
for i:=0 to length(ps)-1 do Begin
|
||||||
node := class(xlsxXml).GetNode(ps[i].node_, uri);
|
node := class(TSXml).GetNode(ps[i].node_, uri);
|
||||||
if ifObj(node) then Begin
|
if ifObj(node) then Begin
|
||||||
chart := TOfficeObj('TChart');
|
chart := TOfficeObj('TChart');
|
||||||
chart.Init(self, ps[i].node_, node);
|
chart.Init(self, ps[i].node_, node);
|
||||||
|
|
@ -289,11 +291,11 @@ Type TSDocxFile = Class
|
||||||
<w:comments xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData" mc:Ignorable="w14 w15 wp14"></w:comments>');
|
<w:comments xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData" mc:Ignorable="w14 w15 wp14"></w:comments>');
|
||||||
rels := 'word/_rels/document.xml.rels';
|
rels := 'word/_rels/document.xml.rels';
|
||||||
xmlfile := zipfile_.Get(rels);
|
xmlfile := zipfile_.Get(rels);
|
||||||
[rId, target] := class(xlsxXml).FindRelationshipRid(xmlfile, '');
|
[rId, target] := class(TSXml).FindRelationshipRid(xmlfile, '');
|
||||||
rId ++;
|
rId ++;
|
||||||
class(xlsxXml).AddRelationshipRid(xmlfile, 'comments.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', 'rId' $ rId);
|
class(TSXml).AddRelationshipRid(xmlfile, 'comments.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', 'rId' $ rId);
|
||||||
contentType := zipfile_.Get('[Content_Types].xml');
|
contentType := zipfile_.Get('[Content_Types].xml');
|
||||||
class(xlsxXml).AddOverrideContentType(contentType, '/word/comments.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml');
|
class(TSXml).AddOverrideContentType(contentType, '/word/comments.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml');
|
||||||
End
|
End
|
||||||
xmlfile := zipfile_.Get(file);
|
xmlfile := zipfile_.Get(file);
|
||||||
id := 0;
|
id := 0;
|
||||||
|
|
@ -307,33 +309,54 @@ Type TSDocxFile = Class
|
||||||
c := TOfficeObj('TDocComment');
|
c := TOfficeObj('TDocComment');
|
||||||
c.p.Run.SetText( txt );
|
c.p.Run.SetText( txt );
|
||||||
c.Author := author;
|
c.Author := author;
|
||||||
if author and not class(xlsxXml).IsUtf8() then
|
if author and not class(TSXml).IsUtf8() then
|
||||||
c.Author := class(xlsxXml).CurCodePageToUtf8(author);
|
c.Author := class(TSXml).CurCodePageToUtf8(author);
|
||||||
c.ID := id;
|
c.ID := id;
|
||||||
xmlfile.FirstChildElement('w:comments').InsertEndChild(c.Marshal());
|
xmlfile.FirstChildElement('w:comments').InsertEndChild(c.Marshal());
|
||||||
return c;
|
return c;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///格式刷:复制段落格式(包括字体格式)
|
///格式刷:段落格式 + 字体格式
|
||||||
///fromParagraph:源段落
|
///fromParagraph:源段落
|
||||||
///toParagraph:目标段落
|
///toParagraph:目标段落
|
||||||
Function CopyFormat(fromParagraph, toParagraph);
|
Function CopyFormat(fromParagraph, toParagraph);
|
||||||
Begin
|
Begin
|
||||||
toParagraph.ClearFormat();//清除目标段落格式、字体格式
|
toParagraph.ClearFormat();//清除目标段落格式、字体格式
|
||||||
|
CopyParagraphFormat(fromParagraph, toParagraph);//段落格式
|
||||||
|
//字体格式
|
||||||
|
if not ifObj(fromParagraph) then
|
||||||
|
return;
|
||||||
|
fromRun := fromParagraph.GetRun(0);
|
||||||
|
if ifObj(fromRun) then Begin
|
||||||
|
runs := toParagraph.GetRuns();
|
||||||
|
for i:=0 to length(runs)-1 do Begin
|
||||||
|
runs[i].CopyFontFormat(fromRun);
|
||||||
|
End;
|
||||||
|
End;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///格式刷:仅段落格式
|
||||||
|
///fromParagraph:源段落
|
||||||
|
///toParagraph:目标段落
|
||||||
|
Function CopyParagraphFormat(fromParagraph, toParagraph);
|
||||||
|
Begin
|
||||||
|
pPr := toParagraph.node_.FirstChildElement('w:pPr');
|
||||||
|
//清除段落格式
|
||||||
|
if ifObj(pPr) then
|
||||||
|
toParagraph.node_.DeleteChild(pPr);
|
||||||
pPr := ifObj(fromParagraph) ? fromParagraph.node_.FirstChildElement('w:pPr') : nil;
|
pPr := ifObj(fromParagraph) ? fromParagraph.node_.FirstChildElement('w:pPr') : nil;
|
||||||
if ifObj(pPr) then Begin //复制段落格式
|
if ifObj(pPr) then Begin //复制段落格式
|
||||||
pPr2 := toParagraph.node_.InsertFirstChild('element', 'w:pPr');
|
|
||||||
arr := pPr.Marshal();
|
arr := pPr.Marshal();
|
||||||
class(xlsxXml).UpdateNode(pPr2, arr[0]['attributes'], arr[0]['children']);
|
toParagraph.node_.InsertFirstChild(arr[0]);
|
||||||
End;
|
End;
|
||||||
//复制字体格式
|
|
||||||
rPr := ifObj(fromParagraph) ? class(xlsxXml).GetNode(fromParagraph.node_, 'w:r/w:rPr') : nil;
|
|
||||||
if ifObj(rPr) then Begin
|
|
||||||
r := rPr.Marshal();
|
|
||||||
runs := toParagraph.GetRuns();
|
|
||||||
for i:=0 to length(runs)-1 do
|
|
||||||
toParagraph._copyFormat(runs[i].node_, r, false);
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
///格式刷:仅字体格式
|
||||||
|
///fromRun:源段落
|
||||||
|
///toRun:目标段落
|
||||||
|
Function CopyFontFormat(fromRun, toRun);
|
||||||
|
Begin
|
||||||
|
toRun.CopyFontFormat(fromRun);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加目录
|
///添加目录
|
||||||
|
|
@ -346,9 +369,7 @@ Type TSDocxFile = Class
|
||||||
Begin
|
Begin
|
||||||
content := new TTableContent(self);
|
content := new TTableContent(self);
|
||||||
content.SetDefaultFormat(); //缺省目录格式
|
content.SetDefaultFormat(); //缺省目录格式
|
||||||
node := posOpt;
|
node := getPosNode(posOpt);
|
||||||
if ifObj(posOpt) and not (posOpt is Class(XmlNode)) then
|
|
||||||
node := posOpt.Node();
|
|
||||||
content.Add(node, UpperHeadingLevel, LowerHeadingLevel); //标题级别
|
content.Add(node, UpperHeadingLevel, LowerHeadingLevel); //标题级别
|
||||||
if ifObj(node) then
|
if ifObj(node) then
|
||||||
content.node_ := document_.Body().node_.InsertAfterChild(node, content.Marshal());
|
content.node_ := document_.Body().node_.InsertAfterChild(node, content.Marshal());
|
||||||
|
|
@ -389,6 +410,13 @@ Type TSDocxFile = Class
|
||||||
return numberingObj_;
|
return numberingObj_;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
///执行word文档内嵌tsl代码
|
||||||
|
///返回:[err,tslFuncCount,errArr]: err 执行错误TSL代码段次数,tslFuncCount TSL代码段总数,errArr 执行TSL错误信息(包括代码、错误信息)
|
||||||
|
Function ExecInnerTSL();
|
||||||
|
Begin
|
||||||
|
return Body().ExecInnerTSL(self);
|
||||||
|
End;
|
||||||
|
|
||||||
Function ZipObject();
|
Function ZipObject();
|
||||||
Begin
|
Begin
|
||||||
return zipfile_;
|
return zipfile_;
|
||||||
|
|
@ -398,10 +426,40 @@ Type TSDocxFile = Class
|
||||||
Begin
|
Begin
|
||||||
return ExtractFileDir(ExtractFileDir(PluginPath()));
|
return ExtractFileDir(ExtractFileDir(PluginPath()));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Function GetDocPrId();
|
||||||
|
Begin
|
||||||
|
if DocPrId_ < 0 then Begin
|
||||||
|
DocPrId_ := 0;
|
||||||
|
ps := Paragraphs();
|
||||||
|
for i:=0 to length(ps)-1 do Begin
|
||||||
|
node := class(TSXml).GetNode(ps[i].node_, 'w:r/w:drawing/wp:inline/wp:docPr');
|
||||||
|
if not ifObj(node) then
|
||||||
|
node := class(TSXml).GetNode(ps[i].node_, 'w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr');
|
||||||
|
if ifObj(node) then Begin
|
||||||
|
id := class(TSXml).SafeStrToIntDef(node.GetAttribute('id'), 0);
|
||||||
|
if id > DocPrId_ then
|
||||||
|
DocPrId_ := id;
|
||||||
|
break;
|
||||||
|
End;
|
||||||
|
End;
|
||||||
|
End;
|
||||||
|
DocPrId_ ++;
|
||||||
|
return DocPrId_;
|
||||||
|
End;
|
||||||
|
private
|
||||||
|
Function getPosNode(posOpt);
|
||||||
|
Begin
|
||||||
|
node := posOpt;
|
||||||
|
if ifObj(node) and not (node is Class(XmlNode)) then
|
||||||
|
node := node.Node();
|
||||||
|
return node;
|
||||||
|
End;
|
||||||
private
|
private
|
||||||
zipfile_; //压缩文件对象
|
zipfile_; //压缩文件对象
|
||||||
document_; //Document对象
|
document_; //Document对象
|
||||||
xml_; //xlsxXml对象
|
xml_; //TSXml对象
|
||||||
styleObj_;
|
styleObj_;
|
||||||
numberingObj_;
|
numberingObj_;
|
||||||
|
DocPrId_;
|
||||||
End;
|
End;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Version 1.0.5
|
// Version 1.0.6
|
||||||
|
|
||||||
Type TSExcelFile = Class
|
Type TSExcelFile = Class
|
||||||
///Version: V1.0 2022-08-08
|
///Version: V1.0 2022-08-08
|
||||||
|
|
@ -90,7 +90,7 @@ Type TSExcelFile = Class
|
||||||
sheets := workbook_.GetSheets();
|
sheets := workbook_.GetSheets();
|
||||||
for i:=0 to length(sheets)-1 do
|
for i:=0 to length(sheets)-1 do
|
||||||
begin
|
begin
|
||||||
sheets[i] := class(xlsxXml).Utf8ToCurCodePage(sheets[i]);
|
sheets[i] := class(TSXml).Utf8ToCurCodePage(sheets[i]);
|
||||||
end
|
end
|
||||||
return sheets;
|
return sheets;
|
||||||
End;
|
End;
|
||||||
|
|
@ -108,30 +108,29 @@ Type TSExcelFile = Class
|
||||||
Function GetSheetName(index);
|
Function GetSheetName(index);
|
||||||
Begin
|
Begin
|
||||||
name := workbook_.GetSheetName(index);
|
name := workbook_.GetSheetName(index);
|
||||||
return class(xlsxXml).Utf8ToCurCodePage(name);
|
return class(TSXml).Utf8ToCurCodePage(name);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///创建新sheet
|
///创建新sheet
|
||||||
///sheet: string,工作表名称
|
///sheet: string,工作表名称
|
||||||
Function NewSheet(sheet);
|
Function NewSheet(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.NewSheet(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.NewSheet(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///删除sheet
|
///删除sheet
|
||||||
///sheet: string,工作表名称
|
///sheet: string,工作表名称
|
||||||
Function DeleteSheet(sheet);
|
Function DeleteSheet(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.DeleteSheet(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.DeleteSheet(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置工作表名
|
///设置工作表名
|
||||||
///sourceName: string, 原工作表名
|
///sourceName: string, 原工作表名
|
||||||
///destName: string,目标工作表名
|
///destName: string,目标工作表名
|
||||||
///返回: [err, errinfo]
|
|
||||||
Function SetSheetName(sourceName, destName);
|
Function SetSheetName(sourceName, destName);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetSheetName(class(xlsxXml).CurCodePageToUtf8(sourceName), class(xlsxXml).CurCodePageToUtf8(destName));
|
return workbook_.SetSheetName(class(TSXml).CurCodePageToUtf8(sourceName), class(TSXml).CurCodePageToUtf8(destName));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取总列数
|
///获取总列数
|
||||||
|
|
@ -139,7 +138,7 @@ Type TSExcelFile = Class
|
||||||
///返回: int
|
///返回: int
|
||||||
Function TotalCols(sheet);
|
Function TotalCols(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.TotalCols(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.TotalCols(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取总行数
|
///获取总行数
|
||||||
|
|
@ -147,7 +146,7 @@ Type TSExcelFile = Class
|
||||||
///返回: int
|
///返回: int
|
||||||
Function TotalRows(sheet);
|
Function TotalRows(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.TotalRows(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.TotalRows(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取单元格的值
|
///获取单元格的值
|
||||||
|
|
@ -156,8 +155,8 @@ Type TSExcelFile = Class
|
||||||
///返回: [err, value:string]
|
///返回: [err, value:string]
|
||||||
Function GetCellValue(sheet, axis);
|
Function GetCellValue(sheet, axis);
|
||||||
Begin
|
Begin
|
||||||
[err, value] := workbook_.GetCellValue(class(xlsxXml).CurCodePageToUtf8(sheet), axis);
|
[err, value] := workbook_.GetCellValue(class(TSXml).CurCodePageToUtf8(sheet), axis);
|
||||||
if not err then return array(err, class(xlsxXml).Utf8ToCurCodePage(value));
|
if not err then return array(err, class(TSXml).Utf8ToCurCodePage(value));
|
||||||
return array(err, value);
|
return array(err, value);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -173,8 +172,8 @@ Type TSExcelFile = Class
|
||||||
/// 属性s:单元格样式
|
/// 属性s:单元格样式
|
||||||
Function SetCellValue(sheet, axis, val, opt);
|
Function SetCellValue(sheet, axis, val, opt);
|
||||||
Begin
|
Begin
|
||||||
sheet_name := class(xlsxXml).CurCodePageToUtf8(sheet);
|
sheet_name := class(TSXml).CurCodePageToUtf8(sheet);
|
||||||
value := class(xlsxXml).CurCodePageToUtf8(val);
|
value := class(TSXml).CurCodePageToUtf8(val);
|
||||||
return workbook_.SetCellValue(sheet_name, axis, value, opt);
|
return workbook_.SetCellValue(sheet_name, axis, value, opt);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -184,9 +183,9 @@ Type TSExcelFile = Class
|
||||||
///返回: [err, richtxt:string],参见SetCellRichText
|
///返回: [err, richtxt:string],参见SetCellRichText
|
||||||
Function GetCellRichText(sheet, axis);
|
Function GetCellRichText(sheet, axis);
|
||||||
Begin
|
Begin
|
||||||
[err, str] := workbook_.GetCellRichText(class(xlsxXml).CurCodePageToUtf8(sheet), axis);
|
[err, str] := workbook_.GetCellRichText(class(TSXml).CurCodePageToUtf8(sheet), axis);
|
||||||
if err then return array(err, str);
|
if err then return array(err, str);
|
||||||
else return array(err, class(xlsxXml).Utf8ToCurCodePage(str));
|
else return array(err, class(TSXml).Utf8ToCurCodePage(str));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置富文本格式
|
///设置富文本格式
|
||||||
|
|
@ -195,13 +194,13 @@ Type TSExcelFile = Class
|
||||||
///richtext: string,xml串或富文本对象TSOfficeObj('TRichText')
|
///richtext: string,xml串或富文本对象TSOfficeObj('TRichText')
|
||||||
Function SetCellRichText(sheet, axis, richtext);
|
Function SetCellRichText(sheet, axis, richtext);
|
||||||
Begin
|
Begin
|
||||||
o := workbook_.GetSheetObj(class(xlsxXml).CurCodePageToUtf8(sheet));
|
o := workbook_.GetSheetObj(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
if ifObj(o) then
|
if ifObj(o) then
|
||||||
begin
|
begin
|
||||||
xml := richtext;
|
xml := richtext;
|
||||||
if ifObj(richtext) then
|
if ifObj(richtext) then
|
||||||
xml := class(xlsxXml).Dom2Xml(richtext.Marshal());
|
xml := class(TSXml).Dom2Xml(richtext.Marshal());
|
||||||
return o.SetCellValue(axis, class(xlsxXml).CurCodePageToUtf8(xml), array('t':'s'), 'RichText');
|
return o.SetCellValue(axis, xml, array('t':'s'), 'RichText');
|
||||||
end
|
end
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -214,7 +213,7 @@ Type TSExcelFile = Class
|
||||||
/// 用法3:ClearCell('A5', 'D8'); //Clear矩形区间所有单元格
|
/// 用法3:ClearCell('A5', 'D8'); //Clear矩形区间所有单元格
|
||||||
Function ClearCell(sheet, topLeft, bottomRight);
|
Function ClearCell(sheet, topLeft, bottomRight);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.ClearCell(class(xlsxXml).CurCodePageToUtf8(sheet), topLeft, bottomRight);
|
return workbook_.ClearCell(class(TSXml).CurCodePageToUtf8(sheet), topLeft, bottomRight);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置公式
|
///设置公式
|
||||||
|
|
@ -223,7 +222,7 @@ Type TSExcelFile = Class
|
||||||
///formula: string,公式
|
///formula: string,公式
|
||||||
Function SetCellFormula(sheet, axis, formula);
|
Function SetCellFormula(sheet, axis, formula);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetCellFormula(class(xlsxXml).CurCodePageToUtf8(sheet), axis, formula);
|
return workbook_.SetCellFormula(class(TSXml).CurCodePageToUtf8(sheet), axis, formula);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取公式
|
///获取公式
|
||||||
|
|
@ -232,7 +231,7 @@ Type TSExcelFile = Class
|
||||||
///返回: [err, formula:string]
|
///返回: [err, formula:string]
|
||||||
Function GetCellFormula(sheet, axis);
|
Function GetCellFormula(sheet, axis);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetCellFormula(class(xlsxXml).CurCodePageToUtf8(sheet), axis);
|
return workbook_.GetCellFormula(class(TSXml).CurCodePageToUtf8(sheet), axis);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///按行赋值
|
///按行赋值
|
||||||
|
|
@ -305,7 +304,7 @@ Type TSExcelFile = Class
|
||||||
///返回: table
|
///返回: table
|
||||||
Function GetTable(sheet, topLeft, bottomRight);
|
Function GetTable(sheet, topLeft, bottomRight);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetTable(class(xlsxXml).CurCodePageToUtf8(sheet), topLeft, bottomRight);
|
return workbook_.GetTable(class(TSXml).CurCodePageToUtf8(sheet), topLeft, bottomRight);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入列,在指定列前插入空白列
|
///插入列,在指定列前插入空白列
|
||||||
|
|
@ -313,7 +312,7 @@ Type TSExcelFile = Class
|
||||||
///col: string 列名,如: "D"
|
///col: string 列名,如: "D"
|
||||||
Function InsertCol(sheet, col);
|
Function InsertCol(sheet, col);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.InsertCol(class(xlsxXml).CurCodePageToUtf8(sheet), col);
|
return workbook_.InsertCol(class(TSXml).CurCodePageToUtf8(sheet), col);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///插入行,在指定行前插入空白行
|
///插入行,在指定行前插入空白行
|
||||||
|
|
@ -321,7 +320,7 @@ Type TSExcelFile = Class
|
||||||
///row: int
|
///row: int
|
||||||
Function InsertRow(sheet, row);
|
Function InsertRow(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.InsertRow(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.InsertRow(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///删除列
|
///删除列
|
||||||
|
|
@ -329,7 +328,7 @@ Type TSExcelFile = Class
|
||||||
///col: string,如: "D"
|
///col: string,如: "D"
|
||||||
Function RemoveCol(sheet, col);
|
Function RemoveCol(sheet, col);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.RemoveCol(class(xlsxXml).CurCodePageToUtf8(sheet), col);
|
return workbook_.RemoveCol(class(TSXml).CurCodePageToUtf8(sheet), col);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///删除行
|
///删除行
|
||||||
|
|
@ -337,7 +336,7 @@ Type TSExcelFile = Class
|
||||||
///row: int
|
///row: int
|
||||||
Function RemoveRow(sheet, row);
|
Function RemoveRow(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.RemoveRow(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.RemoveRow(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置行高度
|
///设置行高度
|
||||||
|
|
@ -346,7 +345,7 @@ Type TSExcelFile = Class
|
||||||
///height: double,行高[0-409]
|
///height: double,行高[0-409]
|
||||||
Function SetRowHeight(sheet, row, height);
|
Function SetRowHeight(sheet, row, height);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetRowHeight(class(xlsxXml).CurCodePageToUtf8(sheet), row, height);
|
return workbook_.SetRowHeight(class(TSXml).CurCodePageToUtf8(sheet), row, height);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取行高度
|
///获取行高度
|
||||||
|
|
@ -355,7 +354,7 @@ Type TSExcelFile = Class
|
||||||
///返回: double
|
///返回: double
|
||||||
Function GetRowHeight(sheet, row);
|
Function GetRowHeight(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetRowHeight(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.GetRowHeight(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置列宽度
|
///设置列宽度
|
||||||
|
|
@ -365,7 +364,7 @@ Type TSExcelFile = Class
|
||||||
///width: double,列宽[0-255]
|
///width: double,列宽[0-255]
|
||||||
Function SetColWidth(sheet, startCol, endCol, width);
|
Function SetColWidth(sheet, startCol, endCol, width);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetColWidth(class(xlsxXml).CurCodePageToUtf8(sheet), startCol, endCol, width);
|
return workbook_.SetColWidth(class(TSXml).CurCodePageToUtf8(sheet), startCol, endCol, width);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取列宽度
|
///获取列宽度
|
||||||
|
|
@ -374,7 +373,7 @@ Type TSExcelFile = Class
|
||||||
///返回: double
|
///返回: double
|
||||||
Function GetColWidth(sheet, col);
|
Function GetColWidth(sheet, col);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetColWidth(class(xlsxXml).CurCodePageToUtf8(sheet), col);
|
return workbook_.GetColWidth(class(TSXml).CurCodePageToUtf8(sheet), col);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置工作表默认列宽
|
///设置工作表默认列宽
|
||||||
|
|
@ -382,7 +381,7 @@ Type TSExcelFile = Class
|
||||||
///width: double
|
///width: double
|
||||||
Function SetSheetDefaultColWidth(sheet, width);
|
Function SetSheetDefaultColWidth(sheet, width);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetSheetDefaultColWidth(class(xlsxXml).CurCodePageToUtf8(sheet), width);
|
return workbook_.SetSheetDefaultColWidth(class(TSXml).CurCodePageToUtf8(sheet), width);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取工作表默认列宽
|
///获取工作表默认列宽
|
||||||
|
|
@ -390,7 +389,7 @@ Type TSExcelFile = Class
|
||||||
///返回: double
|
///返回: double
|
||||||
Function GetSheetDefaultColWidth(sheet);
|
Function GetSheetDefaultColWidth(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetSheetDefaultColWidth(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.GetSheetDefaultColWidth(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加批注
|
///添加批注
|
||||||
|
|
@ -419,7 +418,7 @@ Type TSExcelFile = Class
|
||||||
///返回: [err, ChartList]
|
///返回: [err, ChartList]
|
||||||
Function GetCharts(sheet);
|
Function GetCharts(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetCharts(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.GetCharts(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///单元格坐标切分
|
///单元格坐标切分
|
||||||
|
|
@ -500,7 +499,7 @@ Type TSExcelFile = Class
|
||||||
///styleid: string,样式Id
|
///styleid: string,样式Id
|
||||||
Function SetCellStyle(sheet, topLeft, bottomRight, styleid);
|
Function SetCellStyle(sheet, topLeft, bottomRight, styleid);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetCellStyle(class(xlsxXml).CurCodePageToUtf8(sheet), topLeft, bottomRight, styleid);
|
return workbook_.SetCellStyle(class(TSXml).CurCodePageToUtf8(sheet), topLeft, bottomRight, styleid);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取单元格样式Id,获取到的Id可以在复制单元格样式时,作为调用 SetCellValue、或SetCellStyle 函数的参数使用。
|
///获取单元格样式Id,获取到的Id可以在复制单元格样式时,作为调用 SetCellValue、或SetCellStyle 函数的参数使用。
|
||||||
|
|
@ -509,7 +508,7 @@ Type TSExcelFile = Class
|
||||||
///返回: styleId: string
|
///返回: styleId: string
|
||||||
Function GetCellStyle(sheet, axis);
|
Function GetCellStyle(sheet, axis);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetCellStyle(class(xlsxXml).CurCodePageToUtf8(sheet), axis);
|
return workbook_.GetCellStyle(class(TSXml).CurCodePageToUtf8(sheet), axis);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置工作表页眉页脚
|
///设置工作表页眉页脚
|
||||||
|
|
@ -526,7 +525,7 @@ Type TSExcelFile = Class
|
||||||
///visible: boolean
|
///visible: boolean
|
||||||
Function SetSheetVisible(sheet, visible);
|
Function SetSheetVisible(sheet, visible);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetSheetVisible(class(xlsxXml).CurCodePageToUtf8(sheet), visible);
|
return workbook_.SetSheetVisible(class(TSXml).CurCodePageToUtf8(sheet), visible);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取工作表可见性
|
///获取工作表可见性
|
||||||
|
|
@ -534,7 +533,7 @@ Type TSExcelFile = Class
|
||||||
///visibility: boolean
|
///visibility: boolean
|
||||||
Function GetSheetVisible(sheet);
|
Function GetSheetVisible(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetSheetVisible(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.GetSheetVisible(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置行可见性
|
///设置行可见性
|
||||||
|
|
@ -543,7 +542,7 @@ Type TSExcelFile = Class
|
||||||
///visible: boolean
|
///visible: boolean
|
||||||
Function SetRowVisible(sheet, row, visible)
|
Function SetRowVisible(sheet, row, visible)
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetRowVisible(class(xlsxXml).CurCodePageToUtf8(sheet), row, visible);
|
return workbook_.SetRowVisible(class(TSXml).CurCodePageToUtf8(sheet), row, visible);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取工作表行可见性
|
///获取工作表行可见性
|
||||||
|
|
@ -552,7 +551,7 @@ Type TSExcelFile = Class
|
||||||
///返回: [err, visible:boolean]
|
///返回: [err, visible:boolean]
|
||||||
Function GetRowVisble(sheet, row);
|
Function GetRowVisble(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.GetRowVisble(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.GetRowVisble(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置列可见性
|
///设置列可见性
|
||||||
|
|
@ -563,7 +562,7 @@ Type TSExcelFile = Class
|
||||||
Begin
|
Begin
|
||||||
[err, col] := ColumnNameToNumber(col);
|
[err, col] := ColumnNameToNumber(col);
|
||||||
if err then return "Col error.";
|
if err then return "Col error.";
|
||||||
return workbook_.SetColVisible(class(xlsxXml).CurCodePageToUtf8(sheet), col, visible);
|
return workbook_.SetColVisible(class(TSXml).CurCodePageToUtf8(sheet), col, visible);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取列可见性
|
///获取列可见性
|
||||||
|
|
@ -574,7 +573,7 @@ Type TSExcelFile = Class
|
||||||
Begin
|
Begin
|
||||||
[err, col] := ColumnNameToNumber(col);
|
[err, col] := ColumnNameToNumber(col);
|
||||||
if err then return array(-1, col);
|
if err then return array(-1, col);
|
||||||
return workbook_.GetColVisble(class(xlsxXml).CurCodePageToUtf8(sheet), col);
|
return workbook_.GetColVisble(class(TSXml).CurCodePageToUtf8(sheet), col);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置工作表页边距
|
///设置工作表页边距
|
||||||
|
|
@ -602,7 +601,7 @@ Type TSExcelFile = Class
|
||||||
///vcell: string,右下角坐标
|
///vcell: string,右下角坐标
|
||||||
Function MergeCell(sheet, hcell, vcell);
|
Function MergeCell(sheet, hcell, vcell);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.MergeCell(class(xlsxXml).CurCodePageToUtf8(sheet), hcell, vcell);
|
return workbook_.MergeCell(class(TSXml).CurCodePageToUtf8(sheet), hcell, vcell);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///取消合并单元格
|
///取消合并单元格
|
||||||
|
|
@ -611,7 +610,7 @@ Type TSExcelFile = Class
|
||||||
///vcell: string,右下角坐标
|
///vcell: string,右下角坐标
|
||||||
Function UnMergeCell(sheet, hcell, vcell);
|
Function UnMergeCell(sheet, hcell, vcell);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.UnMergeCell(class(xlsxXml).CurCodePageToUtf8(sheet), hcell, vcell);
|
return workbook_.UnMergeCell(class(TSXml).CurCodePageToUtf8(sheet), hcell, vcell);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置工作表视图属性
|
///设置工作表视图属性
|
||||||
|
|
@ -641,7 +640,7 @@ Type TSExcelFile = Class
|
||||||
Function SetPageLayout(sheet, pageLayout);
|
Function SetPageLayout(sheet, pageLayout);
|
||||||
Begin
|
Begin
|
||||||
o := getOj(sheet, 'xlsxPageLayout');
|
o := getOj(sheet, 'xlsxPageLayout');
|
||||||
if ifObj(o) then return o.SetPageLayout(class(xlsxXml).CurCodePageToUtf8(sheet), pageLayout);
|
if ifObj(o) then return o.SetPageLayout(class(TSXml).CurCodePageToUtf8(sheet), pageLayout);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取工作表页面设置
|
///获取工作表页面设置
|
||||||
|
|
@ -657,7 +656,7 @@ Type TSExcelFile = Class
|
||||||
///sheet: string,工作表名称
|
///sheet: string,工作表名称
|
||||||
Function SetDefaultSheet(sheet);
|
Function SetDefaultSheet(sheet);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.SetDefaultSheet(class(xlsxXml).CurCodePageToUtf8(sheet));
|
return workbook_.SetDefaultSheet(class(TSXml).CurCodePageToUtf8(sheet));
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///获取默认工作表
|
///获取默认工作表
|
||||||
|
|
@ -665,7 +664,7 @@ Type TSExcelFile = Class
|
||||||
Function GetDefaultSheet();
|
Function GetDefaultSheet();
|
||||||
Begin
|
Begin
|
||||||
sheet := workbook_.GetDefaultSheet();
|
sheet := workbook_.GetDefaultSheet();
|
||||||
return class(xlsxXml).Utf8ToCurCodePage(sheet);
|
return class(TSXml).Utf8ToCurCodePage(sheet);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///设置超链接
|
///设置超链接
|
||||||
|
|
@ -737,7 +736,7 @@ Type TSExcelFile = Class
|
||||||
///row: int,行号
|
///row: int,行号
|
||||||
Function InsertPageBreak(sheet, row);
|
Function InsertPageBreak(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.InsertPageBreak(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.InsertPageBreak(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///删除指定行分页符
|
///删除指定行分页符
|
||||||
|
|
@ -745,7 +744,7 @@ Type TSExcelFile = Class
|
||||||
///row: int,行号
|
///row: int,行号
|
||||||
Function RemovePageBreak(sheet, row);
|
Function RemovePageBreak(sheet, row);
|
||||||
Begin
|
Begin
|
||||||
return workbook_.RemovePageBreak(class(xlsxXml).CurCodePageToUtf8(sheet), row);
|
return workbook_.RemovePageBreak(class(TSXml).CurCodePageToUtf8(sheet), row);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加形状
|
///添加形状
|
||||||
|
|
@ -805,7 +804,7 @@ Type TSExcelFile = Class
|
||||||
private
|
private
|
||||||
Function getOj(sheet, objname);
|
Function getOj(sheet, objname);
|
||||||
Begin
|
Begin
|
||||||
sheetname := class(xlsxXml).CurCodePageToUtf8(sheet);
|
sheetname := class(TSXml).CurCodePageToUtf8(sheet);
|
||||||
if not ifarray(objMgr_) then objMgr_:= array();
|
if not ifarray(objMgr_) then objMgr_:= array();
|
||||||
k := sheetname + '.' + objname;
|
k := sheetname + '.' + objname;
|
||||||
o := objMgr_[ k ];
|
o := objMgr_[ k ];
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ public
|
||||||
if ifObj(RootObj) then Begin
|
if ifObj(RootObj) then Begin
|
||||||
arr := Marshal();
|
arr := Marshal();
|
||||||
if length(arr['attributes']) or length(arr['children']) then Begin
|
if length(arr['attributes']) or length(arr['children']) then Begin
|
||||||
class(xlsxXml).UpdateNode(RootObj, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(RootObj, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
@ -166,7 +166,7 @@ public
|
||||||
lName := lowerCase(name);
|
lName := lowerCase(name);
|
||||||
r := sselect * from attrs where lName = lowerCase([0]) end;
|
r := sselect * from attrs where lName = lowerCase([0]) end;
|
||||||
if istable(r) then Begin
|
if istable(r) then Begin
|
||||||
node := class(xlsxXml).GetNode(rootNode, uri);
|
node := class(TSXml).GetNode(rootNode, uri);
|
||||||
if not ifObj(node) then return nil;
|
if not ifObj(node) then return nil;
|
||||||
return node.GetAttribute(r[1]);
|
return node.GetAttribute(r[1]);
|
||||||
End;
|
End;
|
||||||
|
|
@ -176,7 +176,7 @@ public
|
||||||
if istable(r) then Begin
|
if istable(r) then Begin
|
||||||
r := r[0];
|
r := r[0];
|
||||||
uri := (uri='' ? '' : uri + '/') + r['name'];
|
uri := (uri='' ? '' : uri + '/') + r['name'];
|
||||||
node := class(xlsxXml).GetNode(rootNode, uri);
|
node := class(TSXml).GetNode(rootNode, uri);
|
||||||
if not ifObj(node) then return nil;
|
if not ifObj(node) then return nil;
|
||||||
if r['nodeType'] = 'empty' then
|
if r['nodeType'] = 'empty' then
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,194 @@
|
||||||
|
Function TOfficeApi();
|
||||||
|
Begin
|
||||||
|
if not ifObj(sysparams['TOffice sys api']) then
|
||||||
|
sysparams['TOffice sys api'] := new TOffice();
|
||||||
|
return sysparams['TOffice sys api'];
|
||||||
|
End;
|
||||||
|
|
||||||
|
Type TOffice = Class
|
||||||
|
Function Create();
|
||||||
|
Begin
|
||||||
|
hash_ := array();
|
||||||
|
End;
|
||||||
|
|
||||||
|
///检测当前环境字符集
|
||||||
|
///调用规范:TOfficeApi().CodePage('中文');
|
||||||
|
Function CodePage(zw);
|
||||||
|
Begin
|
||||||
|
cp := 'utf8';//默认环境为UTF8格式
|
||||||
|
str := StrToBase64(zw);
|
||||||
|
case str of
|
||||||
|
'1tDOxA==':
|
||||||
|
cp := 'gbk';
|
||||||
|
'5Lit5paH':
|
||||||
|
cp := 'utf8';
|
||||||
|
'pKSk5Q==':
|
||||||
|
cp := 'big5';
|
||||||
|
End;
|
||||||
|
hash_['CodePage'] := cp;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///当前环境是否UTF8
|
||||||
|
Function IsUtf8();
|
||||||
|
Begin
|
||||||
|
if ifnil(hash_['CodePage']) or hash_['CodePage'] = 'utf8' then
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获得当前文档对象:TDocxFile对象
|
||||||
|
Function GetDocument();
|
||||||
|
Begin
|
||||||
|
return hash_['Docx'];
|
||||||
|
End;
|
||||||
|
|
||||||
|
///设置当前段落标签
|
||||||
|
///name:string 标签名称
|
||||||
|
Function SetParagraphTag(name);
|
||||||
|
Begin
|
||||||
|
hash_['Paragraph-Node-' + name] := hash_['CurrentParagraph'];
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段所在段落
|
||||||
|
///返回:TParagraph对象
|
||||||
|
Function GetCurrentParagraph();
|
||||||
|
Begin
|
||||||
|
node := hash_['CurrentParagraph'];
|
||||||
|
if not ifObj(node) then
|
||||||
|
return nil;
|
||||||
|
p := TOfficeObj('TParagraph');
|
||||||
|
p.Init(node);
|
||||||
|
return p;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段所在段落的w:r元素
|
||||||
|
///返回:TRun对象
|
||||||
|
Function GetCurrentRun();
|
||||||
|
Begin
|
||||||
|
node := hash_['CurrentRun'];
|
||||||
|
if not ifObj(node) then
|
||||||
|
return nil;
|
||||||
|
p := TOfficeObj('TRun');
|
||||||
|
p.Init(node);
|
||||||
|
return p;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取指定标签段落
|
||||||
|
///name:string 标签名称
|
||||||
|
///返回:TParagraph对象
|
||||||
|
Function GetParagraph(name);
|
||||||
|
Begin
|
||||||
|
node := hash_['Paragraph-Node-' + name];
|
||||||
|
if not ifObj(node) then
|
||||||
|
return nil;
|
||||||
|
p := TOfficeObj('TParagraph');
|
||||||
|
p.Init(node);
|
||||||
|
return p;
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段上一个表格
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TTable对象
|
||||||
|
Function GetPrevTable(p);
|
||||||
|
Begin
|
||||||
|
return getTableImpl(p, false);
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段下一个表格
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TTable对象
|
||||||
|
Function GetNextTable(p);
|
||||||
|
Begin
|
||||||
|
return getTableImpl(p, true);
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段上一张图片
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TPicture对象
|
||||||
|
Function GetPrevPicture(p);
|
||||||
|
Begin
|
||||||
|
return getPictureImpl(p, false);
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段下一张图片
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TPicture对象
|
||||||
|
Function GetNextPicture(p);
|
||||||
|
Begin
|
||||||
|
return getPictureImpl(p, true);
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段上一个Chart图
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TChart对象
|
||||||
|
Function GetPrevChart(p);
|
||||||
|
Begin
|
||||||
|
return getChartImpl(p, false);
|
||||||
|
End;
|
||||||
|
|
||||||
|
///获取当前TSL代码段下一个Chart图
|
||||||
|
///[p]:可选参数,为Nil指当前段落
|
||||||
|
///返回:TChart对象
|
||||||
|
Function GetNextChart(p);
|
||||||
|
Begin
|
||||||
|
return getChartImpl(p, true);
|
||||||
|
End;
|
||||||
|
|
||||||
|
Function Set(k, v);
|
||||||
|
Begin
|
||||||
|
hash_[k] := v;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Function Get(k);
|
||||||
|
Begin
|
||||||
|
return hash_[k];
|
||||||
|
End;
|
||||||
|
private
|
||||||
|
Function getTableImpl(p, next);
|
||||||
|
Begin
|
||||||
|
if not ifObj(p) then
|
||||||
|
p := GetCurrentParagraph();
|
||||||
|
node := next ? p.node_.NextElement('w:tbl') : p.node_.PrevElement('w:tbl');
|
||||||
|
if not ifObj(node) then
|
||||||
|
return nil;
|
||||||
|
tbl := TOfficeObj('TTable');
|
||||||
|
tbl.Init(node);
|
||||||
|
return tbl;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Function getPictureImpl(p, next);
|
||||||
|
Begin
|
||||||
|
if not ifObj(p) then
|
||||||
|
p := GetCurrentParagraph();
|
||||||
|
node := next ? p.node_.NextElement('w:p') : p.node_.PrevElement('w:p');
|
||||||
|
while ifObj(node) do Begin
|
||||||
|
draw := class(TSXml).GetNode(node, 'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/pic:pic');
|
||||||
|
if ifObj(draw) then Begin
|
||||||
|
p := TOfficeObj('TPicture');
|
||||||
|
p.Init(node);
|
||||||
|
return p;
|
||||||
|
End;
|
||||||
|
node := next ? p.node.NextElement('w:p') : p.node.PrevElement('w:p');
|
||||||
|
End;
|
||||||
|
return nil;
|
||||||
|
End;
|
||||||
|
|
||||||
|
Function getChartImpl(p, next);
|
||||||
|
Begin
|
||||||
|
if not ifObj(p) then
|
||||||
|
p := GetCurrentParagraph();
|
||||||
|
node := next ? p.node_.NextElement('w:p') : p.node_.PrevElement('w:p');
|
||||||
|
while ifObj(node) do Begin
|
||||||
|
chartNode := class(TSXml).GetNode(node, 'w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart');
|
||||||
|
if ifObj(chartNode) then Begin
|
||||||
|
p := TOfficeObj('TChart');
|
||||||
|
p.Init(hash_['Docx'], node, chartNode);
|
||||||
|
return p;
|
||||||
|
End;
|
||||||
|
node := next ? p.node.NextElement('w:p') : p.node.PrevElement('w:p');
|
||||||
|
End;
|
||||||
|
return nil;
|
||||||
|
End;
|
||||||
|
|
||||||
|
hash_;
|
||||||
|
End;
|
||||||
|
|
@ -103,7 +103,7 @@ Type TSChart = Class
|
||||||
Function Apply(xmlObj);
|
Function Apply(xmlObj);
|
||||||
Begin
|
Begin
|
||||||
chartData_.Serialize(IsWord()); //初始化图表数据
|
chartData_.Serialize(IsWord()); //初始化图表数据
|
||||||
task := array(('c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t', 'pcdata', class(xlsxXml).CurCodePageToUtf8(chartData_.Title)),
|
task := array(('c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t', 'pcdata', class(TSXml).CurCodePageToUtf8(chartData_.Title)),
|
||||||
('c:chartSpace/c:chart/c:plotVisOnly', 'val', chartData_.plotVisOnly),
|
('c:chartSpace/c:chart/c:plotVisOnly', 'val', chartData_.plotVisOnly),
|
||||||
('c:chartSpace/c:chart/c:dispBlanksAs', 'val', chartData_.ShowBlanksAs),
|
('c:chartSpace/c:chart/c:dispBlanksAs', 'val', chartData_.ShowBlanksAs),
|
||||||
('c:chartSpace/c:chart/c:legend', 'Del', ifnil(chartData_.Legend)),
|
('c:chartSpace/c:chart/c:legend', 'Del', ifnil(chartData_.Legend)),
|
||||||
|
|
@ -111,16 +111,16 @@ Type TSChart = Class
|
||||||
('c:chartSpace/c:chart/c:view3D', 'unmarshal', getview3D().Marshal())
|
('c:chartSpace/c:chart/c:view3D', 'unmarshal', getview3D().Marshal())
|
||||||
);
|
);
|
||||||
for i:=0 to length(task)-1 do Begin
|
for i:=0 to length(task)-1 do Begin
|
||||||
class(xlsxXml).SetNodeValue(xmlObj, task[i]);
|
class(TSXml).SetNodeValue(xmlObj, task[i]);
|
||||||
End;
|
End;
|
||||||
if ifObj(chartData_.Legend) then Begin
|
if ifObj(chartData_.Legend) then Begin
|
||||||
node := class(xlsxXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:legend');
|
node := class(TSXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:legend');
|
||||||
if ifObj(node) then Begin
|
if ifObj(node) then Begin
|
||||||
arr := chartData_.Legend.Marshal();
|
arr := chartData_.Legend.Marshal();
|
||||||
class(xlsxXml).UpdateNode(node, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(node, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
chartData_.ChartNode := class(xlsxXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:plotArea');
|
chartData_.plotAreaNode := class(TSXml).GetNode(xmlObj, 'c:chartSpace/c:chart/c:plotArea');
|
||||||
if chartData_.DataTable then
|
if chartData_.DataTable then
|
||||||
chartData_.ShowDataTable(true);
|
chartData_.ShowDataTable(true);
|
||||||
End;
|
End;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
Type xlsxXml = Class
|
Type TSXml = Class
|
||||||
class Function XmlHeader();
|
class Function XmlHeader();
|
||||||
Begin
|
Begin
|
||||||
return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> \n';
|
return '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> \n';
|
||||||
|
|
@ -28,14 +28,14 @@ Type xlsxXml = Class
|
||||||
|
|
||||||
class Function GetFileName(key);
|
class Function GetFileName(key);
|
||||||
Begin
|
Begin
|
||||||
map := class(xlsxXml).GetMap();
|
map := class(TSXml).GetMap();
|
||||||
if ifarray(map[key]) then return map[key]['FileName'];
|
if ifarray(map[key]) then return map[key]['FileName'];
|
||||||
return '';
|
return '';
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function GetTemplate(key);
|
class Function GetTemplate(key);
|
||||||
Begin
|
Begin
|
||||||
map := class(xlsxXml).GetMap();
|
map := class(TSXml).GetMap();
|
||||||
if ifarray(map[key]) then return map[key]['Template'];
|
if ifarray(map[key]) then return map[key]['Template'];
|
||||||
return '';
|
return '';
|
||||||
End;
|
End;
|
||||||
|
|
@ -106,7 +106,7 @@ Type xlsxXml = Class
|
||||||
if children[i]['type'] = 'pcdata' then
|
if children[i]['type'] = 'pcdata' then
|
||||||
child.SetValue(children[i]['value']);
|
child.SetValue(children[i]['value']);
|
||||||
else
|
else
|
||||||
class(xlsxXml).UpdateNode(child, children[i]['attributes'], children[i]['children']);
|
class(TSXml).UpdateNode(child, children[i]['attributes'], children[i]['children']);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -166,7 +166,7 @@ Type xlsxXml = Class
|
||||||
End;
|
End;
|
||||||
node := node.NextElement();
|
node := node.NextElement();
|
||||||
End;
|
End;
|
||||||
return array(rID, findtarget);
|
return array(rID, findtarget, i);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function FindRelationship(xmlfile, rid);
|
class Function FindRelationship(xmlfile, rid);
|
||||||
|
|
@ -180,6 +180,14 @@ Type xlsxXml = Class
|
||||||
return nil;
|
return nil;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
class Function FindRelationshipTarget(xmlfile, rid);
|
||||||
|
Begin
|
||||||
|
node := class(TSXml).FindRelationship(xmlfile, rid);
|
||||||
|
if ifObj(node) then
|
||||||
|
return node.GetAttribute('Target');
|
||||||
|
return nil;
|
||||||
|
End;
|
||||||
|
|
||||||
class Function AddRelationshipRid(xmlfile, target, type, rid, targetMode);
|
class Function AddRelationshipRid(xmlfile, target, type, rid, targetMode);
|
||||||
Begin
|
Begin
|
||||||
node := xmlfile.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship');
|
node := xmlfile.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship');
|
||||||
|
|
@ -306,36 +314,24 @@ Type xlsxXml = Class
|
||||||
|
|
||||||
class Function CodePage(zw);
|
class Function CodePage(zw);
|
||||||
Begin
|
Begin
|
||||||
cp := 'utf8';//默认环境为UTF8格式
|
TOfficeApi().CodePage(zw);
|
||||||
str := StrToBase64(zw);
|
|
||||||
case str of
|
|
||||||
'1tDOxA==':
|
|
||||||
cp := 'gbk';
|
|
||||||
'5Lit5paH':
|
|
||||||
cp := 'utf8';
|
|
||||||
'pKSk5Q==':
|
|
||||||
cp := 'big5';
|
|
||||||
End;
|
|
||||||
sysparams['CodePage'] := cp;
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function IsUtf8();
|
class Function IsUtf8();
|
||||||
Begin
|
Begin
|
||||||
if ifnil(sysparams['CodePage']) or sysparams['CodePage'] = 'utf8' then
|
return TOfficeApi().IsUtf8();
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function Utf8ToCurCodePage(str);
|
class Function Utf8ToCurCodePage(str);
|
||||||
Begin
|
Begin
|
||||||
if ifstring(str) and not class(xlsxXml).IsUtf8() then
|
if ifstring(str) and not class(TSXml).IsUtf8() then
|
||||||
return UTF8ToAnsi(str);
|
return UTF8ToAnsi(str);
|
||||||
return str;
|
return str;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function CurCodePageToUtf8(str);
|
class Function CurCodePageToUtf8(str);
|
||||||
Begin
|
Begin
|
||||||
if ifstring(str) and not class(xlsxXml).IsUtf8() then
|
if ifstring(str) and not class(TSXml).IsUtf8() then
|
||||||
return AnsiToUTF8(str);
|
return AnsiToUTF8(str);
|
||||||
return str;
|
return str;
|
||||||
End;
|
End;
|
||||||
|
|
@ -2,23 +2,28 @@ Type TDocxChart = Class(TSChart)
|
||||||
///缺省构造函数
|
///缺省构造函数
|
||||||
Function Create(docx, chartData); overload;
|
Function Create(docx, chartData); overload;
|
||||||
Begin
|
Begin
|
||||||
|
docx_ := docx;
|
||||||
class(TSChart).Create(chartData);
|
class(TSChart).Create(chartData);
|
||||||
//chartN.xml
|
//chartN.xml
|
||||||
chartId_ := 1 + vselect countof( ['FileName'] ) from docx.ZipObject().Files() where AnsiStartsText('word/charts/chart', ['FileName']) end;
|
chartId_ := 1 + vselect countof( ['FileName'] ) from docx.ZipObject().Files() where AnsiStartsText('word/charts/chart', ['FileName']) end;
|
||||||
chartFile := 'word/charts/chart' $ chartId_ $ '.xml';
|
targetFileName := 'charts/chart' $ chartId_ $ '.xml';
|
||||||
|
chartFile := 'word/' + targetFileName;
|
||||||
docx.ZipObject().Add(chartFile, GetDefaultXml());
|
docx.ZipObject().Add(chartFile, GetDefaultXml());
|
||||||
xmlObj := docx.ZipObject().Get(chartFile);
|
xmlObj_ := docx.ZipObject().Get(chartFile);
|
||||||
Apply(xmlObj);
|
if not chartData_.DisableExcel and istable(chartData.Series) and istable(chartData.Series[0]['Categories']) and istable(chartData.Series[0]['Values']) then Begin
|
||||||
|
//chartData_.NewExcelFile();
|
||||||
|
End;
|
||||||
|
Apply(xmlObj_);
|
||||||
|
addExternalData();
|
||||||
|
|
||||||
//Relationship
|
//Relationship
|
||||||
relsObj := docx.ZipObject().Get('word/_rels/document.xml.rels');
|
relsObj := docx.ZipObject().Get('word/_rels/document.xml.rels');
|
||||||
[rId_, target] := class(xlsxXml).FindRelationshipRid(relsObj, '');
|
[rId_, target] := class(TSXml).FindRelationshipRid(relsObj, '');
|
||||||
rId_ ++;
|
rId_ ++;
|
||||||
class(xlsxXml).AddRelationshipRid(relsObj, '/' + chartFile, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', 'rId' $ rId_);
|
class(TSXml).AddRelationshipRid(relsObj, targetFileName, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', 'rId' $ rId_);
|
||||||
|
|
||||||
//Content_Types
|
//Content_Types
|
||||||
contentType := docx.ZipObject().Get('[Content_Types].xml');
|
contentType := docx.ZipObject().Get('[Content_Types].xml');
|
||||||
class(xlsxXml).AddOverrideContentType(contentType, '/' + chartFile, 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
|
class(TSXml).AddOverrideContentType(contentType, '/' + chartFile, 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function GetInnerXml();
|
Function GetInnerXml();
|
||||||
|
|
@ -33,12 +38,12 @@ Type TDocxChart = Class(TSChart)
|
||||||
<wp:cNvGraphicFramePr />
|
<wp:cNvGraphicFramePr />
|
||||||
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
|
<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
|
||||||
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
|
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/chart">
|
||||||
<c:chart xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId{}" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"/>
|
<c:chart xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:id="rId{}"/>
|
||||||
</a:graphicData>
|
</a:graphicData>
|
||||||
</a:graphic>
|
</a:graphic>
|
||||||
</wp:inline>
|
</wp:inline>
|
||||||
</w:drawing>
|
</w:drawing>
|
||||||
</w:r>', integer(chartData_.Width * ETU), integer(chartData_.Height * ETU), chartId_, class(xlsxXml).CurCodePageToUtf8(chartData_.Name), rId_);
|
</w:r>', integer(chartData_.Width * ETU), integer(chartData_.Height * ETU), docx_.GetDocPrId(), class(TSXml).CurCodePageToUtf8(chartData_.Name), rId_);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function IsWord();override;
|
Function IsWord();override;
|
||||||
|
|
@ -46,6 +51,33 @@ Type TDocxChart = Class(TSChart)
|
||||||
return true;
|
return true;
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
Function addExternalData();
|
||||||
|
Begin
|
||||||
|
//内嵌excel数据文件
|
||||||
|
if not ifObj(chartData_.Excel) then
|
||||||
|
return;
|
||||||
|
[err, data] := chartData_.Excel.Zip().Save2Mem();
|
||||||
|
if err then
|
||||||
|
return;
|
||||||
|
xmlObj_.FirstChildElement('c:chartSpace').InsertEndChild('<c:externalData r:id="rId1"><c:autoUpdate val="0"/></c:externalData>');
|
||||||
|
rels := 'word/charts/_rels/chart' $ chartId_ $ '.xml.rels';
|
||||||
|
xmlStr := '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
||||||
|
<Relationship Target="../embeddings/Workbook1.xlsx" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Id="rId1"/>
|
||||||
|
</Relationships>';
|
||||||
|
fileCnt := 1 + vselect countof( ['FileName'] ) from docx_.ZipObject().Files() where AnsiStartsText('word/embeddings/Workbook', ['FileName']) end;
|
||||||
|
workBook := 'embeddings/Workbook' $ fileCnt $ '.xlsx';
|
||||||
|
docx_.ZipObject().Add(rels, xmlStr);
|
||||||
|
if fileCnt > 1 then Begin
|
||||||
|
relsObj := docx_.ZipObject().Get(rels);
|
||||||
|
node := relsObj.FirstChildElement('Relationships').FirstChildElement('Relationship');
|
||||||
|
node.SetAttribute('Target', '../' + workBook);
|
||||||
|
End;
|
||||||
|
docx_.ZipObject().Add('word/' + workBook, data);
|
||||||
|
End;
|
||||||
|
|
||||||
|
docx_;
|
||||||
chartId_;
|
chartId_;
|
||||||
rId_;
|
rId_;
|
||||||
|
xmlObj_;
|
||||||
End;
|
End;
|
||||||
|
|
@ -21,13 +21,13 @@ Type TDocxStyles = Class
|
||||||
_addStyle(o);
|
_addStyle(o);
|
||||||
node := node.NextElement('w:style');
|
node := node.NextElement('w:style');
|
||||||
End;
|
End;
|
||||||
pNode := class(xlsxXml).GetNode(stylesNode, 'w:docDefaults/w:pPrDefault');
|
pNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:pPrDefault');
|
||||||
if ifObj(pNode) then
|
if ifObj(pNode) then
|
||||||
defaultPpr_ := Class(xlsxXml).ReadPprFormat(pNode);
|
defaultPpr_ := Class(TSXml).ReadPprFormat(pNode);
|
||||||
|
|
||||||
rNode := class(xlsxXml).GetNode(stylesNode, 'w:docDefaults/w:rPrDefault');
|
rNode := class(TSXml).GetNode(stylesNode, 'w:docDefaults/w:rPrDefault');
|
||||||
if ifObj(rNode) then
|
if ifObj(rNode) then
|
||||||
defaultRpr_ := Class(xlsxXml).ReadRprFormat(rNode);
|
defaultRpr_ := Class(TSXml).ReadRprFormat(rNode);
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,11 @@ Type TNumbering = Class
|
||||||
docx.ZipObject().Add('word/numbering.xml', xmlData);
|
docx.ZipObject().Add('word/numbering.xml', xmlData);
|
||||||
rels := 'word/_rels/document.xml.rels';
|
rels := 'word/_rels/document.xml.rels';
|
||||||
relsObj := docx.ZipObject().Get(rels);
|
relsObj := docx.ZipObject().Get(rels);
|
||||||
[rId, target] := class(xlsxXml).FindRelationshipRid(relsObj, '');
|
[rId, target] := class(TSXml).FindRelationshipRid(relsObj, '');
|
||||||
rId ++;
|
rId ++;
|
||||||
class(xlsxXml).AddRelationshipRid(relsObj, 'numbering.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering', 'rId' $ rId);
|
class(TSXml).AddRelationshipRid(relsObj, 'numbering.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering', 'rId' $ rId);
|
||||||
contentType := docx.ZipObject().Get('[Content_Types].xml');
|
contentType := docx.ZipObject().Get('[Content_Types].xml');
|
||||||
class(xlsxXml).AddOverrideContentType(contentType, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml');
|
class(TSXml).AddOverrideContentType(contentType, '/word/numbering.xml', 'application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml');
|
||||||
numberingXml_ := docx.ZipObject().Get('word/numbering.xml');
|
numberingXml_ := docx.ZipObject().Get('word/numbering.xml');
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
@ -216,7 +216,7 @@ Type TNumbering = Class
|
||||||
o.nsid := id;
|
o.nsid := id;
|
||||||
o.tmpl := id;
|
o.tmpl := id;
|
||||||
arr := o.Marshal();
|
arr := o.Marshal();
|
||||||
class(xlsxXml).UpdateNode(o.node_, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(o.node_, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
private
|
private
|
||||||
docx_;
|
docx_;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ Type TTableContent = class
|
||||||
//_CheckNodes('endnotes.xml');
|
//_CheckNodes('endnotes.xml');
|
||||||
//_CheckNodes('footnotes.xml');
|
//_CheckNodes('footnotes.xml');
|
||||||
//contentType := docx.ZipObject().Get('[Content_Types].xml');
|
//contentType := docx.ZipObject().Get('[Content_Types].xml');
|
||||||
//class(xlsxXml).AddOverrideContentType(contentType, 'wmf', 'image/x-wmf');
|
//class(TSXml).AddOverrideContentType(contentType, 'wmf', 'image/x-wmf');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function SetDefaultFormat();
|
Function SetDefaultFormat();
|
||||||
|
|
@ -43,7 +43,7 @@ Type TTableContent = class
|
||||||
Function Apply(); override;
|
Function Apply(); override;
|
||||||
Begin
|
Begin
|
||||||
arr := impl_.Marshal();
|
arr := impl_.Marshal();
|
||||||
class(xlsxXml).UpdateNode(node_, arr['attributes'], arr['children']);
|
class(TSXml).UpdateNode(node_, arr['attributes'], arr['children']);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
///添加目录条目
|
///添加目录条目
|
||||||
|
|
@ -287,18 +287,18 @@ Type TTableContent = class
|
||||||
z.Add('word/' + name, xmlData);
|
z.Add('word/' + name, xmlData);
|
||||||
rels := 'word/_rels/document.xml.rels';
|
rels := 'word/_rels/document.xml.rels';
|
||||||
relsObj := z.Get(rels);
|
relsObj := z.Get(rels);
|
||||||
[rId, target] := class(xlsxXml).FindRelationshipRid(relsObj, '');
|
[rId, target] := class(TSXml).FindRelationshipRid(relsObj, '');
|
||||||
rId ++;
|
rId ++;
|
||||||
|
|
||||||
if name = 'endnotes.xml' then Begin
|
if name = 'endnotes.xml' then Begin
|
||||||
class(xlsxXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes', 'rId' $ rId);
|
class(TSXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes', 'rId' $ rId);
|
||||||
contentType := z.Get('[Content_Types].xml');
|
contentType := z.Get('[Content_Types].xml');
|
||||||
class(xlsxXml).AddOverrideContentType(contentType, '/word/' + name, 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml');
|
class(TSXml).AddOverrideContentType(contentType, '/word/' + name, 'application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml');
|
||||||
End
|
End
|
||||||
else if name = 'footnotes.xml' then Begin
|
else if name = 'footnotes.xml' then Begin
|
||||||
class(xlsxXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes', 'rId' $ rId);
|
class(TSXml).AddRelationshipRid(relsObj, name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes', 'rId' $ rId);
|
||||||
contentType := z.Get('[Content_Types].xml');
|
contentType := z.Get('[Content_Types].xml');
|
||||||
class(xlsxXml).AddOverrideContentType(contentType, '/word/' + name, 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml');
|
class(TSXml).AddOverrideContentType(contentType, '/word/' + name, 'application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml');
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ Apply()函数可以修改属性值,例如:
|
||||||
|
|
||||||
*如何设置字符集(中文支持)?
|
*如何设置字符集(中文支持)?
|
||||||
★用户的脚本可能是UFT8格式,或可能是GBK码格式,系统提供API自动设置当前字符集环境:
|
★用户的脚本可能是UFT8格式,或可能是GBK码格式,系统提供API自动设置当前字符集环境:
|
||||||
class(xlsxXml).CodePage('中文'); //系统检测当前的环境字符集
|
TOfficeApi().CodePage('中文'); //系统检测当前的环境字符集
|
||||||
...
|
...
|
||||||
p.Run.SetText('系统可以自动识别这里的中文字符集(utf8或gbk)!');
|
p.Run.SetText('系统可以自动识别这里的中文字符集(utf8或gbk)!');
|
||||||
★不设置,默认当前字符集为UTF8
|
★不设置,默认当前字符集为UTF8
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ Type xlsxChart = Class(TSChart)
|
||||||
drawingRID_ := excel_.WorkBook().GetSheetDrawing(sheet);
|
drawingRID_ := excel_.WorkBook().GetSheetDrawing(sheet);
|
||||||
drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawingRID_ $ '.xml');
|
drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawingRID_ $ '.xml');
|
||||||
drawingRelsObj := excel_.WorkBook().GetDrawingRelsFile(drawingRID_);
|
drawingRelsObj := excel_.WorkBook().GetDrawingRelsFile(drawingRID_);
|
||||||
[chartRid_, find] := class(xlsxXml).FindRelationshipRid(drawingRelsObj, '');
|
[chartRid_, find] := class(TSXml).FindRelationshipRid(drawingRelsObj, '');
|
||||||
chartRid_ ++;
|
chartRid_ ++;
|
||||||
class(xlsxXml).AddRelationshipRid(drawingRelsObj, '../charts/chart'+inttostr(chartId_)+'.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', 'rId' + inttostr(chartRid_));
|
class(TSXml).AddRelationshipRid(drawingRelsObj, '../charts/chart'+inttostr(chartId_)+'.xml', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', 'rId' + inttostr(chartRid_));
|
||||||
xlChartFileName_ := 'xl/charts/chart'+inttostr(chartId_)+'.xml';
|
xlChartFileName_ := 'xl/charts/chart'+inttostr(chartId_)+'.xml';
|
||||||
content_xml := excel_.WorkBook().GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := excel_.WorkBook().GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddOverrideContentType(content_xml, '/' + xlChartFileName_, 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
|
class(TSXml).AddOverrideContentType(content_xml, '/' + xlChartFileName_, 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
class Function NewObject(sheet, excel);
|
class Function NewObject(sheet, excel);
|
||||||
|
|
@ -49,7 +49,7 @@ Type xlsxChart = Class(TSChart)
|
||||||
|
|
||||||
o.GraphicFrame.macro := '';
|
o.GraphicFrame.macro := '';
|
||||||
o.GraphicFrame.GraphicFramePr.Name := chartData.Name ? chartData.Name : 'Chart' + inttostr(chartId_);
|
o.GraphicFrame.GraphicFramePr.Name := chartData.Name ? chartData.Name : 'Chart' + inttostr(chartId_);
|
||||||
o.GraphicFrame.GraphicFramePr.Id := class(xlsxXml).GetcNvPrID(drawingXmlObj_);
|
o.GraphicFrame.GraphicFramePr.Id := class(TSXml).GetcNvPrID(drawingXmlObj_);
|
||||||
o.GraphicFrame.GraphicFramePr.cNvGraphicFramePr := true;
|
o.GraphicFrame.GraphicFramePr.cNvGraphicFramePr := true;
|
||||||
|
|
||||||
o.GraphicFrame.XFrm.Off.X := 0;
|
o.GraphicFrame.XFrm.Off.X := 0;
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ Type xlsxComment = Class
|
||||||
commentId_ := excel_.WorkBook().GetFilesCount('xl/comments') + 1;
|
commentId_ := excel_.WorkBook().GetFilesCount('xl/comments') + 1;
|
||||||
commentFileName_ := '../comments' + inttostr(commentId_) + '.xml';
|
commentFileName_ := '../comments' + inttostr(commentId_) + '.xml';
|
||||||
xlCommentFileName := 'xl/comments' + inttostr(commentId_) + '.xml';
|
xlCommentFileName := 'xl/comments' + inttostr(commentId_) + '.xml';
|
||||||
excel_.Zip().Add(xlCommentFileName, class(xlsxXml).XmlHeader() + '<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"></comments>');
|
excel_.Zip().Add(xlCommentFileName, class(TSXml).XmlHeader() + '<comments xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"></comments>');
|
||||||
excel_.WorkBook().AddRelationshipRid(relsfile, commentFileName_, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', rId_);
|
excel_.WorkBook().AddRelationshipRid(relsfile, commentFileName_, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', rId_);
|
||||||
rid ++;
|
rid ++;
|
||||||
drawingVML_ := '../drawings/vmlDrawing' + inttostr(commentId_) + '.vml';
|
drawingVML_ := '../drawings/vmlDrawing' + inttostr(commentId_) + '.vml';
|
||||||
|
|
@ -33,9 +33,9 @@ xmlns:v="urn:schemas-microsoft-com:vml">
|
||||||
</v:shapetype>
|
</v:shapetype>
|
||||||
</xml>');
|
</xml>');
|
||||||
excel_.WorkBook().AddRelationshipRid(relsfile, drawingVML_, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing', 'rId' + inttostr(rid));
|
excel_.WorkBook().AddRelationshipRid(relsfile, drawingVML_, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing', 'rId' + inttostr(rid));
|
||||||
content_xml := excel_.WorkBook().GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := excel_.WorkBook().GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddOverrideContentType(content_xml, '/' + xlCommentFileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml');
|
class(TSXml).AddOverrideContentType(content_xml, '/' + xlCommentFileName, 'application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml');
|
||||||
class(xlsxXml).AddDefaultContentType(content_xml, 'vml', 'application/vnd.openxmlformats-officedocument.vmlDrawing');
|
class(TSXml).AddDefaultContentType(content_xml, 'vml', 'application/vnd.openxmlformats-officedocument.vmlDrawing');
|
||||||
|
|
||||||
sheetXml := excel_.WorkBook().GetSheetXmlfile(sheetName_).FirstChildElement('worksheet');
|
sheetXml := excel_.WorkBook().GetSheetXmlfile(sheetName_).FirstChildElement('worksheet');
|
||||||
legacy := sheetXml.FirstChildElement('legacyDrawing');
|
legacy := sheetXml.FirstChildElement('legacyDrawing');
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ Type xlsxDocProps = Class
|
||||||
node := app_xml.FirstChildElement('Properties');
|
node := app_xml.FirstChildElement('Properties');
|
||||||
if not ifObj(node) then return "node::Properties can't be found";
|
if not ifObj(node) then return "node::Properties can't be found";
|
||||||
marshal := appProps.Marshal();
|
marshal := appProps.Marshal();
|
||||||
class(xlsxXml).UpdateNode(node, marshal['attributes'], marshal['children']);
|
class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function GetAppProps();
|
Function GetAppProps();
|
||||||
|
|
@ -27,7 +27,7 @@ Type xlsxDocProps = Class
|
||||||
core_xml := excel_.WorkBook().GetXmlFileObj('docProps/core.xml');
|
core_xml := excel_.WorkBook().GetXmlFileObj('docProps/core.xml');
|
||||||
node := core_xml.FirstChildElement('cp:coreProperties');
|
node := core_xml.FirstChildElement('cp:coreProperties');
|
||||||
marshal := appProps.Marshal();
|
marshal := appProps.Marshal();
|
||||||
class(xlsxXml).UpdateNode(node, marshal['attributes'], marshal['children']);
|
class(TSXml).UpdateNode(node, marshal['attributes'], marshal['children']);
|
||||||
End
|
End
|
||||||
|
|
||||||
Function GetCoreProps();
|
Function GetCoreProps();
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ Type xlsxHyperLink = Class
|
||||||
work_node := xmlFile_.FirstChildElement('worksheet');
|
work_node := xmlFile_.FirstChildElement('worksheet');
|
||||||
hyperlinks := work_node.FirstChildElement('hyperlinks');
|
hyperlinks := work_node.FirstChildElement('hyperlinks');
|
||||||
if not ifObj(hyperlinks) then begin
|
if not ifObj(hyperlinks) then begin
|
||||||
insert_node := class(xlsxXml).GetWorkSheetPrevNode(work_node, 'hyperlinks');
|
insert_node := class(TSXml).GetWorkSheetPrevNode(work_node, 'hyperlinks');
|
||||||
hyperlinks := work_node.InsertAfterChild(insert_node, 'element', 'hyperlinks');
|
hyperlinks := work_node.InsertAfterChild(insert_node, 'element', 'hyperlinks');
|
||||||
end;
|
end;
|
||||||
node := hyperlinks.FirstChildElement('hyperlink');
|
node := hyperlinks.FirstChildElement('hyperlink');
|
||||||
|
|
@ -44,7 +44,7 @@ Type xlsxHyperLink = Class
|
||||||
rid++;
|
rid++;
|
||||||
ridstr := 'rId' + inttostr(rid);
|
ridstr := 'rId' + inttostr(rid);
|
||||||
xmlfile := file_.WorkBook().GetXmlFileObj(relsfile);
|
xmlfile := file_.WorkBook().GetXmlFileObj(relsfile);
|
||||||
class(xlsxXml).AddRelationshipRid(xmlfile, hyperlink.LinkUrl, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ridstr, "External");
|
class(TSXml).AddRelationshipRid(xmlfile, hyperlink.LinkUrl, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", ridstr, "External");
|
||||||
End
|
End
|
||||||
hyperlink.RId := 'rId' + inttostr(rid);
|
hyperlink.RId := 'rId' + inttostr(rid);
|
||||||
end
|
end
|
||||||
|
|
@ -71,7 +71,7 @@ Type xlsxHyperLink = Class
|
||||||
link.LinkType := 'external';
|
link.LinkType := 'external';
|
||||||
rid := node.GetAttribute('r:id');
|
rid := node.GetAttribute('r:id');
|
||||||
rels_file := file_.WorkBook().GetSheetRelsFile(sheetName_);
|
rels_file := file_.WorkBook().GetSheetRelsFile(sheetName_);
|
||||||
target_node := class(xlsxXml).FindRelationship(rels_file, rid);
|
target_node := class(TSXml).FindRelationship(rels_file, rid);
|
||||||
if ifObj(target_node) then link.LinkUrl := target_node.GetAttribute('Target');
|
if ifObj(target_node) then link.LinkUrl := target_node.GetAttribute('Target');
|
||||||
end
|
end
|
||||||
link.Tooltip := node.GetAttribute('tooltip');
|
link.Tooltip := node.GetAttribute('tooltip');
|
||||||
|
|
|
||||||
|
|
@ -23,21 +23,21 @@ Type xlsxImage = Class
|
||||||
image_file := getImageFileName(picture);
|
image_file := getImageFileName(picture);
|
||||||
rels_xmlfile := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
rels_xmlfile := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
||||||
prefix := ReplaceStr(image_file, 'xl/', '../');
|
prefix := ReplaceStr(image_file, 'xl/', '../');
|
||||||
[rid, target] := class(xlsxXml).FindRelationshipRid(rels_xmlfile, prefix);
|
[rid, target] := class(TSXml).FindRelationshipRid(rels_xmlfile, prefix);
|
||||||
if target = '' then
|
if target = '' then
|
||||||
begin
|
begin
|
||||||
rid ++;
|
rid ++;
|
||||||
class(xlsxXml).AddRelationshipRid(rels_xmlfile, prefix, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid);
|
class(TSXml).AddRelationshipRid(rels_xmlfile, prefix, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid);
|
||||||
end
|
end
|
||||||
content_xml := excel_.WorkBook().GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := excel_.WorkBook().GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddDefaultContentType(content_xml, 'jpeg', 'image/jpeg');
|
class(TSXml).AddDefaultContentType(content_xml, 'jpeg', 'image/jpeg');
|
||||||
|
|
||||||
sheet_xml := excel_.WorkBook().GetSheetXmlfile(sheetName_);
|
sheet_xml := excel_.WorkBook().GetSheetXmlfile(sheetName_);
|
||||||
node := sheet_xml.FirstChildElement('worksheet');
|
node := sheet_xml.FirstChildElement('worksheet');
|
||||||
picture_node := node.FirstChildElement('picture');
|
picture_node := node.FirstChildElement('picture');
|
||||||
if not ifObj(picture_node) then
|
if not ifObj(picture_node) then
|
||||||
begin
|
begin
|
||||||
prev_node := class(xlsxXml).GetWorkSheetPrevNode(node, 'picture');
|
prev_node := class(TSXml).GetWorkSheetPrevNode(node, 'picture');
|
||||||
if ifObj(prev_node) then picture_node := node.InsertAfterChild(prev_node, 'element', 'picture');
|
if ifObj(prev_node) then picture_node := node.InsertAfterChild(prev_node, 'element', 'picture');
|
||||||
else picture_node := node.InsertEndChild('element', 'picture');
|
else picture_node := node.InsertEndChild('element', 'picture');
|
||||||
end
|
end
|
||||||
|
|
@ -55,26 +55,26 @@ Type xlsxImage = Class
|
||||||
image_target := ReplaceStr(getImageFileName(picture), 'xl/', '../');
|
image_target := ReplaceStr(getImageFileName(picture), 'xl/', '../');
|
||||||
drawing_id := excel_.WorkBook().GetSheetDrawing(sheetName_);
|
drawing_id := excel_.WorkBook().GetSheetDrawing(sheetName_);
|
||||||
drawing_rels := excel_.WorkBook().GetDrawingRelsFile(drawing_id);
|
drawing_rels := excel_.WorkBook().GetDrawingRelsFile(drawing_id);
|
||||||
[rid, target] := class(xlsxXml).FindRelationshipRid(drawing_rels, image_target);
|
[rid, target] := class(TSXml).FindRelationshipRid(drawing_rels, image_target);
|
||||||
if target = '' then
|
if target = '' then
|
||||||
begin
|
begin
|
||||||
rid++;
|
rid++;
|
||||||
class(xlsxXml).AddRelationshipRid(drawing_rels, image_target, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid);
|
class(TSXml).AddRelationshipRid(drawing_rels, image_target, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', 'rId' $ rid);
|
||||||
end
|
end
|
||||||
content_xml := excel_.WorkBook().GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := excel_.WorkBook().GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddDefaultContentType(content_xml, 'jpeg', 'image/jpeg');
|
class(TSXml).AddDefaultContentType(content_xml, 'jpeg', 'image/jpeg');
|
||||||
sheet_xml := excel_.WorkBook().GetSheetXmlfile(sheetName_);
|
sheet_xml := excel_.WorkBook().GetSheetXmlfile(sheetName_);
|
||||||
node := sheet_xml.FirstChildElement('worksheet');
|
node := sheet_xml.FirstChildElement('worksheet');
|
||||||
drawing_node := node.FirstChildElement('drawing');
|
drawing_node := node.FirstChildElement('drawing');
|
||||||
if not ifObj(drawing_node) then
|
if not ifObj(drawing_node) then
|
||||||
begin
|
begin
|
||||||
prev_node := class(xlsxXml).GetWorkSheetPrevNode(node, 'drawing');
|
prev_node := class(TSXml).GetWorkSheetPrevNode(node, 'drawing');
|
||||||
if ifObj(prev_node) then drawing_node := node.InsertAfterChild(prev_node, 'element', 'drawing');
|
if ifObj(prev_node) then drawing_node := node.InsertAfterChild(prev_node, 'element', 'drawing');
|
||||||
else drawing_node := node.InsertEndChild('element', 'drawing');
|
else drawing_node := node.InsertEndChild('element', 'drawing');
|
||||||
end
|
end
|
||||||
sheet_rels := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
sheet_rels := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
||||||
drawing_file_name := '../drawings/drawing' + inttostr(drawing_id) + '.xml';
|
drawing_file_name := '../drawings/drawing' + inttostr(drawing_id) + '.xml';
|
||||||
[id, target] := class(xlsxXml).FindRelationshipRid(sheet_rels, drawing_file_name);
|
[id, target] := class(TSXml).FindRelationshipRid(sheet_rels, drawing_file_name);
|
||||||
drawing_node.SetAttribute('r:id', 'rId' + inttostr(id));
|
drawing_node.SetAttribute('r:id', 'rId' + inttostr(id));
|
||||||
|
|
||||||
// drawingN.xml
|
// drawingN.xml
|
||||||
|
|
@ -95,7 +95,7 @@ Type xlsxImage = Class
|
||||||
o.Pic.NodeName := 'xdr:pic';
|
o.Pic.NodeName := 'xdr:pic';
|
||||||
o.Pic.NvPicPr.NodeName := 'xdr:nvPicPr';
|
o.Pic.NvPicPr.NodeName := 'xdr:nvPicPr';
|
||||||
o.Pic.NvPicPr.CNvPr.Name := picture.Name ? picture.Name : '';
|
o.Pic.NvPicPr.CNvPr.Name := picture.Name ? picture.Name : '';
|
||||||
o.Pic.NvPicPr.CNvPr.ID := class(xlsxXml).GetcNvPrID(drawing_xml);
|
o.Pic.NvPicPr.CNvPr.ID := class(TSXml).GetcNvPrID(drawing_xml);
|
||||||
o.Pic.NvPicPr.CNvPr.Descr := picture.Descr ? : '';
|
o.Pic.NvPicPr.CNvPr.Descr := picture.Descr ? : '';
|
||||||
o.Pic.NvPicPr.CNvPr.ExtLst.Ext.Uri := '';
|
o.Pic.NvPicPr.CNvPr.ExtLst.Ext.Uri := '';
|
||||||
o.Pic.NvPicPr.CNvPr.ExtLst.Ext.Xmlns16 := 'http://schemas.microsoft.com/office/drawing/2014/main';
|
o.Pic.NvPicPr.CNvPr.ExtLst.Ext.Xmlns16 := 'http://schemas.microsoft.com/office/drawing/2014/main';
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@ Type xlsxShape = Class
|
||||||
|
|
||||||
class Function NewObject(sheet, excel);
|
class Function NewObject(sheet, excel);
|
||||||
Begin
|
Begin
|
||||||
excel_ := excel;
|
o := excel.WorkBook().GetSheetObj(sheet);//sheet存在
|
||||||
o := excel_.WorkBook().GetSheetObj(sheet);//sheet存在
|
|
||||||
if not ifObj(o) then return 0;
|
if not ifObj(o) then return 0;
|
||||||
return new xlsxShape(sheet, excel);
|
return new xlsxShape(sheet, excel);
|
||||||
End;
|
End;
|
||||||
|
|
@ -68,7 +67,7 @@ private
|
||||||
Function setSpNvSpPr(obj, shapeType);
|
Function setSpNvSpPr(obj, shapeType);
|
||||||
Begin
|
Begin
|
||||||
obj.NodeName := 'xdr:nvSpPr';
|
obj.NodeName := 'xdr:nvSpPr';
|
||||||
obj.CNvPr.ID := class(xlsxXml).GetcNvPrID(drawingXmlObj_);
|
obj.CNvPr.ID := class(TSXml).GetcNvPrID(drawingXmlObj_);
|
||||||
obj.CNvPr.Name := (getShapeInfo()[shapeType]['name'] ?: '') $ ' ' $ obj.CNvPr.ID;
|
obj.CNvPr.Name := (getShapeInfo()[shapeType]['name'] ?: '') $ ' ' $ obj.CNvPr.ID;
|
||||||
obj.CNvPr.ExtLst.Ext.Uri := '';
|
obj.CNvPr.ExtLst.Ext.Uri := '';
|
||||||
obj.CNvPr.ExtLst.Ext.Xmlns16 := 'http://schemas.microsoft.com/office/drawing/2014/main';
|
obj.CNvPr.ExtLst.Ext.Xmlns16 := 'http://schemas.microsoft.com/office/drawing/2014/main';
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ Type xlsxSheetView = Class
|
||||||
if trystrtoint(id, r) and r = viewIndex then
|
if trystrtoint(id, r) and r = viewIndex then
|
||||||
Begin
|
Begin
|
||||||
marshal := SheetView.Marshal();
|
marshal := SheetView.Marshal();
|
||||||
class(xlsxXml).UpdateNode(sheet_view_node, marshal['attributes'], array());
|
class(TSXml).UpdateNode(sheet_view_node, marshal['attributes'], array());
|
||||||
return '';
|
return '';
|
||||||
End
|
End
|
||||||
sheet_view_node := sheet_view_node.NextElement();
|
sheet_view_node := sheet_view_node.NextElement();
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ Type xlsxTable = Class
|
||||||
table_xml := excel_.WorkBook().GetXmlFileObj(table_name);
|
table_xml := excel_.WorkBook().GetXmlFileObj(table_name);
|
||||||
table_node := table_xml.FirstChild('table');
|
table_node := table_xml.FirstChild('table');
|
||||||
marshal := table.Marshal();
|
marshal := table.Marshal();
|
||||||
class(xlsxXml).UpdateNode(table_node, marshal['attributes'], marshal['children']);
|
class(TSXml).UpdateNode(table_node, marshal['attributes'], marshal['children']);
|
||||||
table_node.InsertEndChild(table_str);
|
table_node.InsertEndChild(table_str);
|
||||||
table_node.InsertEndChild(format.Marshal());
|
table_node.InsertEndChild(format.Marshal());
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ Type xlsxTable = Class
|
||||||
count := 1;
|
count := 1;
|
||||||
end
|
end
|
||||||
else begin
|
else begin
|
||||||
count := inttostr(table_part.GetAttribute('count')) + 1;
|
count := strtoint(table_part.GetAttribute('count')) + 1;
|
||||||
end
|
end
|
||||||
node := table_part.InsertEndChild('element', 'tablePart');
|
node := table_part.InsertEndChild('element', 'tablePart');
|
||||||
node.SetAttribute('r:id', 'rId' $ rid);
|
node.SetAttribute('r:id', 'rId' $ rid);
|
||||||
|
|
@ -73,15 +73,16 @@ private
|
||||||
table_str := '<tableColumns count="' $ (endCol - begCol + 1) $ '">';
|
table_str := '<tableColumns count="' $ (endCol - begCol + 1) $ '">';
|
||||||
id := 1;
|
id := 1;
|
||||||
col_index := 1;
|
col_index := 1;
|
||||||
if not includeHeader then
|
if not includeHeader then excel_.WorkBook().InsertRow(sheetName_, row);
|
||||||
begin
|
|
||||||
excel_.WorkBook().InsertRow(sheetName_, row);
|
|
||||||
end
|
|
||||||
for i:=begCol to endCol do
|
for i:=begCol to endCol do
|
||||||
begin
|
begin
|
||||||
[err, cell] := excel_.CoordinatesToCellName(i, row, false);
|
[err, cell] := excel_.CoordinatesToCellName(i, row, false);
|
||||||
if includeHeader then
|
if includeHeader then
|
||||||
name := excel_.WorkBook().GetCellValue(sheetName_, cell)[1];
|
begin
|
||||||
|
[err, name] := excel_.WorkBook().GetCellValue(sheetName_, cell);
|
||||||
|
name := "列" $ col_index++;
|
||||||
|
if err then excel_.WorkBook().SetCellValue(sheetName_, cell, name);
|
||||||
|
end
|
||||||
else begin
|
else begin
|
||||||
name := "列" $ col_index++;
|
name := "列" $ col_index++;
|
||||||
excel_.WorkBook().SetCellValue(sheetName_, cell, name);
|
excel_.WorkBook().SetCellValue(sheetName_, cell, name);
|
||||||
|
|
@ -96,15 +97,15 @@ private
|
||||||
Function addTableXmlFileAndRelation();
|
Function addTableXmlFileAndRelation();
|
||||||
Begin
|
Begin
|
||||||
sheet_rels_file := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
sheet_rels_file := excel_.WorkBook().GetSheetRelsFile(sheetName_);
|
||||||
[rid, target] := class(xlsxXml).FindRelationshipRid(sheet_rels_file, '');
|
[rid, target] := class(TSXml).FindRelationshipRid(sheet_rels_file, '');
|
||||||
rid ++;
|
rid ++;
|
||||||
table_id := excel_.WorkBook().GetFilesCount('xl/tables/') + 1;
|
table_id := excel_.WorkBook().GetFilesCount('xl/tables/') + 1;
|
||||||
table_name := 'xl/tables/table' + inttostr(table_id) + '.xml';
|
table_name := 'xl/tables/table' + inttostr(table_id) + '.xml';
|
||||||
table_target := '../tables/table' + inttostr(table_id) + '.xml';
|
table_target := '../tables/table' + inttostr(table_id) + '.xml';
|
||||||
excel_.zip().Add(table_name, class(xlsxXml).XmlHeader() + "<table />");
|
excel_.zip().Add(table_name, class(TSXml).XmlHeader() + "<table />");
|
||||||
class(xlsxXml).AddRelationshipRid(sheet_rels_file, table_target, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table', 'rId' $ rid);
|
class(TSXml).AddRelationshipRid(sheet_rels_file, table_target, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/table', 'rId' $ rid);
|
||||||
content_xml := excel_.WorkBook().GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := excel_.WorkBook().GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddOverrideContentType(content_xml, '/' + table_name, 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml');
|
class(TSXml).AddOverrideContentType(content_xml, '/' + table_name, 'application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml');
|
||||||
|
|
||||||
return array(rid, table_id, table_name);
|
return array(rid, table_id, table_name);
|
||||||
End
|
End
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ Type xlsxWorkBook = Class
|
||||||
|
|
||||||
//workbook.xml.rels中加载(rid -> sheet-filename)
|
//workbook.xml.rels中加载(rid -> sheet-filename)
|
||||||
rids := array();
|
rids := array();
|
||||||
workbook_rels := GetXmlFileObj(class(xlsxXml).GetFileName('workbook_rels'));
|
workbook_rels := GetXmlFileObj(class(TSXml).GetFileName('workbook_rels'));
|
||||||
rels := workbook_rels.FirstChildElement('Relationships').FirstChildElement('Relationship');
|
rels := workbook_rels.FirstChildElement('Relationships').FirstChildElement('Relationship');
|
||||||
while ifObj(rels) do Begin
|
while ifObj(rels) do Begin
|
||||||
id := rels.GetAttribute('Id');
|
id := rels.GetAttribute('Id');
|
||||||
|
|
@ -138,13 +138,13 @@ Type xlsxWorkBook = Class
|
||||||
sheetId := vselect maxof(['sheetId']) from sheetNames_ end;
|
sheetId := vselect maxof(['sheetId']) from sheetNames_ end;
|
||||||
sheetId := integer(sheetId) + 1;
|
sheetId := integer(sheetId) + 1;
|
||||||
fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml';
|
fname := sheetPrefix_ $ inttostr(sheetsCount_ + 1) $ '.xml';
|
||||||
zipfile_.Add(fname, class(xlsxXml).XmlHeader() + class(xlsxXml).GetTemplate('sheet1'));
|
zipfile_.Add(fname, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('sheet1'));
|
||||||
|
|
||||||
//设置 workbook.xml.rels
|
//设置 workbook.xml.rels
|
||||||
workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels');
|
workbook_rels := GetXmlFileObj('xl/_rels/workbook.xml.rels');
|
||||||
rels := workbook_rels.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship');
|
rels := workbook_rels.FirstChildElement('Relationships').InsertEndChild('element', 'Relationship');
|
||||||
rels.SetAttribute('Target', getTarget( sheetsCount_ + 1));
|
rels.SetAttribute('Target', getTarget( sheetsCount_ + 1));
|
||||||
rels.SetAttribute('Type', class(xlsxXml).GetTemplate('RelationshipWorkSheet'));
|
rels.SetAttribute('Type', class(TSXml).GetTemplate('RelationshipWorkSheet'));
|
||||||
rels.SetAttribute('Id', rid);
|
rels.SetAttribute('Id', rid);
|
||||||
//workbook_rels.Print;
|
//workbook_rels.Print;
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ Type xlsxWorkBook = Class
|
||||||
//workbook.Print();
|
//workbook.Print();
|
||||||
|
|
||||||
//设置docProps/app.xml
|
//设置docProps/app.xml
|
||||||
app := GetXmlFileObj(class(xlsxXml).GetFileName('docProps_app'));
|
app := GetXmlFileObj(class(TSXml).GetFileName('docProps_app'));
|
||||||
//app.Print();
|
//app.Print();
|
||||||
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
||||||
if not ifObj(node) then Begin
|
if not ifObj(node) then Begin
|
||||||
|
|
@ -178,8 +178,8 @@ Type xlsxWorkBook = Class
|
||||||
//app.Print();
|
//app.Print();
|
||||||
|
|
||||||
//设置[Content_Types].xml
|
//设置[Content_Types].xml
|
||||||
content_xml := GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddOverrideContentType(content_xml, '/' + fname, class(xlsxXml).GetTemplate('SheetContentType'));
|
class(TSXml).AddOverrideContentType(content_xml, '/' + fname, class(TSXml).GetTemplate('SheetContentType'));
|
||||||
|
|
||||||
sheetNames_[sheetsCount_]['name'] := sheet;
|
sheetNames_[sheetsCount_]['name'] := sheet;
|
||||||
sheetNames_[sheetsCount_]['sheetId'] := sheetId;
|
sheetNames_[sheetsCount_]['sheetId'] := sheetId;
|
||||||
|
|
@ -224,7 +224,7 @@ Type xlsxWorkBook = Class
|
||||||
f.FileName := files[i]['New-FileName'];
|
f.FileName := files[i]['New-FileName'];
|
||||||
End;
|
End;
|
||||||
End;
|
End;
|
||||||
workbook_rels := GetXmlFileObj(class(xlsxXml).GetFileName('workbook_rels'));
|
workbook_rels := GetXmlFileObj(class(TSXml).GetFileName('workbook_rels'));
|
||||||
parent := workbook_rels.FirstChildElement('Relationships');
|
parent := workbook_rels.FirstChildElement('Relationships');
|
||||||
rels := parent.FirstChildElement('Relationship');
|
rels := parent.FirstChildElement('Relationship');
|
||||||
while ifObj(rels) do Begin
|
while ifObj(rels) do Begin
|
||||||
|
|
@ -266,7 +266,7 @@ Type xlsxWorkBook = Class
|
||||||
//workbook.Print();
|
//workbook.Print();
|
||||||
|
|
||||||
//设置docProps/app.xml
|
//设置docProps/app.xml
|
||||||
app := GetXmlFileObj(class(xlsxXml).GetFileName('docProps_app'));
|
app := GetXmlFileObj(class(TSXml).GetFileName('docProps_app'));
|
||||||
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
||||||
if ifObj(node) then Begin
|
if ifObj(node) then Begin
|
||||||
vector := node.FirstChildElement('vt:vector');
|
vector := node.FirstChildElement('vt:vector');
|
||||||
|
|
@ -330,7 +330,7 @@ Type xlsxWorkBook = Class
|
||||||
End
|
End
|
||||||
|
|
||||||
//设置docProps/app.xml
|
//设置docProps/app.xml
|
||||||
app := GetXmlFileObj(class(xlsxXml).GetFileName('docProps_app'));
|
app := GetXmlFileObj(class(TSXml).GetFileName('docProps_app'));
|
||||||
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
node := app.FirstChildElement('Properties').FirstChildElement('TitlesOfParts');
|
||||||
lpstr := node.FirstChildElement('vt:vector').FirstChildElement('vt:lpstr');
|
lpstr := node.FirstChildElement('vt:vector').FirstChildElement('vt:lpstr');
|
||||||
while ifObj(lpstr) do
|
while ifObj(lpstr) do
|
||||||
|
|
@ -378,7 +378,7 @@ Type xlsxWorkBook = Class
|
||||||
rels := 'xl/worksheets/_rels/sheet' + id + '.xml.rels';
|
rels := 'xl/worksheets/_rels/sheet' + id + '.xml.rels';
|
||||||
if not FileIsExist(rels) then return array(0, array());
|
if not FileIsExist(rels) then return array(0, array());
|
||||||
xmlfile := GetXmlFileObj(rels);
|
xmlfile := GetXmlFileObj(rels);
|
||||||
[rid2, target] := class(xlsxXml).FindRelationshipRid(xmlfile, '../drawings/drawing');
|
[rid2, target] := class(TSXml).FindRelationshipRid(xmlfile, '../drawings/drawing');
|
||||||
if target = '' then return array(0, array());
|
if target = '' then return array(0, array());
|
||||||
drawingFile := ReplaceStr(target, '..', 'xl');
|
drawingFile := ReplaceStr(target, '..', 'xl');
|
||||||
drawingRels := 'xl/drawings/_rels/' + ExtractFileName(target) + '.rels';
|
drawingRels := 'xl/drawings/_rels/' + ExtractFileName(target) + '.rels';
|
||||||
|
|
@ -804,7 +804,7 @@ Type xlsxWorkBook = Class
|
||||||
|
|
||||||
Function DeleteContentType(del_partname);
|
Function DeleteContentType(del_partname);
|
||||||
Begin
|
Begin
|
||||||
content := GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content := GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
types := content.FirstChildElement('Types');
|
types := content.FirstChildElement('Types');
|
||||||
element := types.FirstChildElement('Override');
|
element := types.FirstChildElement('Override');
|
||||||
while ifObj(element) do Begin
|
while ifObj(element) do Begin
|
||||||
|
|
@ -825,10 +825,10 @@ Type xlsxWorkBook = Class
|
||||||
files := zipfile_.Files();
|
files := zipfile_.Files();
|
||||||
isexist := vselect thisrowindex from files where ['FileName']=file end;
|
isexist := vselect thisrowindex from files where ['FileName']=file end;
|
||||||
if ifnil(isexist) then Begin
|
if ifnil(isexist) then Begin
|
||||||
zipfile_.Add(file, class(xlsxXml).XmlHeader() + class(xlsxXml).GetTemplate('sheet_rels'));
|
zipfile_.Add(file, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('sheet_rels'));
|
||||||
end
|
end
|
||||||
xmlfile := GetXmlFileObj(file);
|
xmlfile := GetXmlFileObj(file);
|
||||||
r := class(xlsxXml).FindRelationshipRid(xmlfile, prefix);
|
r := class(TSXml).FindRelationshipRid(xmlfile, prefix);
|
||||||
r[2] := sheetNames_[ind]['file'];
|
r[2] := sheetNames_[ind]['file'];
|
||||||
r[3] := file;
|
r[3] := file;
|
||||||
return r;
|
return r;
|
||||||
|
|
@ -837,7 +837,7 @@ Type xlsxWorkBook = Class
|
||||||
Function AddRelationshipRid(relsfile, target, type, rid);
|
Function AddRelationshipRid(relsfile, target, type, rid);
|
||||||
Begin
|
Begin
|
||||||
xmlfile := GetXmlFileObj(relsfile);
|
xmlfile := GetXmlFileObj(relsfile);
|
||||||
class(xlsxXml).AddRelationshipRid(xmlfile, target, type, rid);
|
class(TSXml).AddRelationshipRid(xmlfile, target, type, rid);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
Function GetFilesCount(prefix);
|
Function GetFilesCount(prefix);
|
||||||
|
|
@ -857,7 +857,7 @@ Type xlsxWorkBook = Class
|
||||||
ind := sheetIndexMap_[LowerCase(sheet)];
|
ind := sheetIndexMap_[LowerCase(sheet)];
|
||||||
file := 'xl/worksheets/_rels/' + ExtractFileName(sheetNames_[ind]['file']) + '.rels';
|
file := 'xl/worksheets/_rels/' + ExtractFileName(sheetNames_[ind]['file']) + '.rels';
|
||||||
if not FileIsExist(file) then
|
if not FileIsExist(file) then
|
||||||
zipfile_.Add(file, class(xlsxXml).XmlHeader() + class(xlsxXml).GetTemplate('sheet_rels'));
|
zipfile_.Add(file, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('sheet_rels'));
|
||||||
return GetXmlFileObj(file);
|
return GetXmlFileObj(file);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -865,7 +865,7 @@ Type xlsxWorkBook = Class
|
||||||
Begin
|
Begin
|
||||||
file := 'xl/drawings/_rels/drawing' + inttostr(drawingId) + '.xml.rels';
|
file := 'xl/drawings/_rels/drawing' + inttostr(drawingId) + '.xml.rels';
|
||||||
if not FileIsExist(drawing_rels) then
|
if not FileIsExist(drawing_rels) then
|
||||||
zipfile_.Add(file, class(xlsxXml).XmlHeader() + class(xlsxXml).GetTemplate('drawing_rels'));
|
zipfile_.Add(file, class(TSXml).XmlHeader() + class(TSXml).GetTemplate('drawing_rels'));
|
||||||
return GetXmlFileObj(file);
|
return GetXmlFileObj(file);
|
||||||
End;
|
End;
|
||||||
|
|
||||||
|
|
@ -899,13 +899,13 @@ Type xlsxWorkBook = Class
|
||||||
drawing_rid := GetFilesCount('xl/drawings/drawing') + 1;
|
drawing_rid := GetFilesCount('xl/drawings/drawing') + 1;
|
||||||
drawing_file_name := '../drawings/drawing' + inttostr(drawing_rid) + '.xml';
|
drawing_file_name := '../drawings/drawing' + inttostr(drawing_rid) + '.xml';
|
||||||
drawing_xl_file_name := 'xl/drawings/drawing' + inttostr(drawing_rid) + '.xml';
|
drawing_xl_file_name := 'xl/drawings/drawing' + inttostr(drawing_rid) + '.xml';
|
||||||
zipfile_.Add(drawing_xl_file_name, class(xlsxXml).XmlHeader() + '<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"></xdr:wsDr>');
|
zipfile_.Add(drawing_xl_file_name, class(TSXml).XmlHeader() + '<xdr:wsDr xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"></xdr:wsDr>');
|
||||||
AddRelationshipRid(relsfile, drawing_file_name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', 'rId' $ inttostr(rid));
|
AddRelationshipRid(relsfile, drawing_file_name, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing', 'rId' $ inttostr(rid));
|
||||||
content_xml := GetXmlFileObj(class(xlsxXml).GetFileName('Content_Types'));
|
content_xml := GetXmlFileObj(class(TSXml).GetFileName('Content_Types'));
|
||||||
class(xlsxXml).AddOverrideContentType(content_xml, '/' + drawing_xl_file_name, 'application/vnd.openxmlformats-officedocument.drawing+xml');
|
class(TSXml).AddOverrideContentType(content_xml, '/' + drawing_xl_file_name, 'application/vnd.openxmlformats-officedocument.drawing+xml');
|
||||||
sheet_xml := GetXmlFileObj(sheet_file_name);
|
sheet_xml := GetXmlFileObj(sheet_file_name);
|
||||||
node := sheet_xml.FirstChildElement('worksheet');
|
node := sheet_xml.FirstChildElement('worksheet');
|
||||||
prev_node := class(xlsxXml).GetWorkSheetPrevNode(node, 'drawing');
|
prev_node := class(TSXml).GetWorkSheetPrevNode(node, 'drawing');
|
||||||
if ifObj(prev_node) then drawing_node := node.InsertAfterChild(prev_node, 'element', 'drawing');
|
if ifObj(prev_node) then drawing_node := node.InsertAfterChild(prev_node, 'element', 'drawing');
|
||||||
else drawing_node := node.InsertEndChild('element', 'drawing');
|
else drawing_node := node.InsertEndChild('element', 'drawing');
|
||||||
drawing_node.SetAttribute('r:id', 'rId' + inttostr(rid));
|
drawing_node.SetAttribute('r:id', 'rId' + inttostr(rid));
|
||||||
|
|
@ -928,7 +928,7 @@ Type xlsxWorkBook = Class
|
||||||
tbreak.Id := row;
|
tbreak.Id := row;
|
||||||
if not ifObj(page_node) then
|
if not ifObj(page_node) then
|
||||||
begin
|
begin
|
||||||
node := class(xlsxXml).GetWorkSheetPrevNode(worksheet, 'rowBreaks');
|
node := class(TSXml).GetWorkSheetPrevNode(worksheet, 'rowBreaks');
|
||||||
node := worksheet.InsertAfterChild(node, 'element', 'rowBreaks');
|
node := worksheet.InsertAfterChild(node, 'element', 'rowBreaks');
|
||||||
node.SetAttribute('count', 1);
|
node.SetAttribute('count', 1);
|
||||||
node.SetAttribute('manualBreakCount', 1);
|
node.SetAttribute('manualBreakCount', 1);
|
||||||
|
|
@ -993,8 +993,8 @@ private
|
||||||
|
|
||||||
Function getWorkbookRelsRid();
|
Function getWorkbookRelsRid();
|
||||||
Begin
|
Begin
|
||||||
workbook_rels := GetXmlFileObj(class(xlsxXml).GetFileName('workbook_rels'));
|
workbook_rels := GetXmlFileObj(class(TSXml).GetFileName('workbook_rels'));
|
||||||
[rId, find] := class(xlsxXml).FindRelationshipRid(workbook_rels, '');
|
[rId, find] := class(TSXml).FindRelationshipRid(workbook_rels, '');
|
||||||
rId ++;
|
rId ++;
|
||||||
return 'rId' $ rId;
|
return 'rId' $ rId;
|
||||||
End;
|
End;
|
||||||
|
|
@ -1030,7 +1030,7 @@ private
|
||||||
chart.C := ifObj(c) ? true : false;
|
chart.C := ifObj(c) ? true : false;
|
||||||
if not ifObj(xml) then return;
|
if not ifObj(xml) then return;
|
||||||
chart.Title := getNodeValue(xml, chart.C ? 'c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t' : 'chartSpace/chart/title/tx/rich/a:p/a:r/a:t', '');
|
chart.Title := getNodeValue(xml, chart.C ? 'c:chartSpace/c:chart/c:title/c:tx/c:rich/a:p/a:r/a:t' : 'chartSpace/chart/title/tx/rich/a:p/a:r/a:t', '');
|
||||||
chart.ChartNode := xml.FirstChildElement(getC(chart) + 'chartSpace').FirstChildElement(getC(chart) + 'chart').FirstChildElement(getC(chart) + 'plotArea');
|
chart.plotAreaNode := xml.FirstChildElement(getC(chart) + 'chartSpace').FirstChildElement(getC(chart) + 'chart').FirstChildElement(getC(chart) + 'plotArea');
|
||||||
End;
|
End;
|
||||||
|
|
||||||
sheetsCount_:integer;
|
sheetsCount_:integer;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue