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