This commit is contained in:
csh
2023-01-18 16:49:57 +08:00
parent 331317b6f6
commit 3146c3c9c5
19 changed files with 1334 additions and 73 deletions
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1,4 +1,4 @@
// Version 1.1.0
// Version 1.1.1
Type TSDocxFile = Class
///Version: V1.0 2022-09-20
@@ -260,7 +260,7 @@ Type TSDocxFile = Class
Function GetCharts();overload;
Begin
r := array();
uri := 'w:p/w:r/w:drawing/wp:inline/a:graphic/a:graphicData/c:chart';
uri := '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(TSXml).GetNode(ps[i].node_, uri);
+19 -5
View File
@@ -1,4 +1,4 @@
// Version 1.1.0
// Version 1.1.1
Type TSExcelFile = Class
///Version: V1.0 2022-08-08
@@ -615,7 +615,7 @@ Type TSExcelFile = Class
///设置工作表视图属性
///sheet: string,工作表名称
///viewIndex: int,视图索引
///viewindex: int,视图索引viewIndex,从0开始
///sheet: objectTSheetView对象
Function SetSheetViewOptions(sheet, viewIndex, sheetView);
Begin
@@ -625,7 +625,6 @@ Type TSExcelFile = Class
///获取工作表视图属性
///sheet: string,工作表名称
///viewindex: int,视图索引,viewIndex 可以是负数,如果是这样,则向后计数(-1 代表最后一个视图)
///返回: object, TSheetView对象
Function GetSheetViewOptions(sheet, viewIndex);
Begin
@@ -634,7 +633,7 @@ Type TSExcelFile = Class
End;
// TODO printerSettings1.bin?
///设置工作表页面设置
///设置工作表页面布局
///sheet: string,工作表名称
///pageLayout: TPageLayout对象,属性:
Function SetPageLayout(sheet, pageLayout);
@@ -643,7 +642,7 @@ Type TSExcelFile = Class
if ifObj(o) then return o.SetPageLayout(class(TSXml).CurCodePageToUtf8(sheet), pageLayout);
End;
///获取工作表页面设置
///获取工作表页面布局
///sheet: string,工作表名称
///返回: TPageLayout对象
Function GetPageLayout(sheet);
@@ -799,6 +798,21 @@ Type TSExcelFile = Class
return workbook_.CopySheet(class(TSXml).CurCodePageToUtf8(sourceSheet), class(TSXml).CurCodePageToUtf8(destSheet));
End;
///保护工作表
///sheet: 工作表
///protect: TProtect对象
Function ProtectSheet(sheet, protect);
Begin
return workbook_.ProtectSheet(class(TSXml).CurCodePageToUtf8(sheet), protect);
End;
///取消保护工作
///sheet: 工作表
Function UnProtectSheet(sheet);
Begin
return workbook_.UnProtectSheet(class(TSXml).CurCodePageToUtf8(sheet));
End;
Function WorkBook();
Begin
return workbook_;
+17 -19
View File
@@ -3,7 +3,10 @@ Type NodeInfo = class
public
Function Create(p, name);
Begin
Parent := p;
if ifObj(p) then
NodeUri := p.NodeUri = '' ? name : (p.NodeUri + '/' + name);
else
NodeUri := '';
NodeName := name;
ExtAttr := array();
ExtNodes := array();
@@ -20,7 +23,9 @@ public
if ifObj(RootObj) then Begin
arr := Marshal();
if length(arr['attributes']) or length(arr['children']) then Begin
class(TSXml).UpdateNode(RootObj, arr['attributes'], arr['children']);
curNode := class(TSXml).GetNode(RootObj, NodeUri);
if ifObj(curNode) then
class(TSXml).UpdateNode(curNode, arr['attributes'], arr['children']);
End;
End;
End;
@@ -152,32 +157,24 @@ public
Function Value(name);
Begin
uri := ifObj(Parent) ? NodeName : '';
p := Parent;
rootNode := Root();
while ifObj(p) do Begin
if ifObj(p.Parent) then
uri := p.NodeName + (uri ? '/' : '') + uri;
rootNode := p.Root();
p := p.Parent;
End;
if not ifObj(rootNode) then return nil;
if not ifObj(RootObj) then return nil;
if NodeUri <> '' then
node := class(TSXml).GetNode(RootObj, NodeUri);
else
node := RootObj;
if not ifObj(node) then return nil;
attrs := GetAttrsEx();
lName := lowerCase(name);
r := sselect * from attrs where lName = lowerCase([0]) end;
if istable(r) then Begin
node := class(TSXml).GetNode(rootNode, uri);
if not ifObj(node) then return nil;
if istable(r) then
return node.GetAttribute(r[1]);
End;
children := GetChildren();
r := select * from children where lName = lowerCase(['field']) end;
if istable(r) then Begin
r := r[0];
uri := (uri='' ? '' : uri + '/') + r['name'];
node := class(TSXml).GetNode(rootNode, uri);
node := node.FirstChildElement(r['name']);
if not ifObj(node) then return nil;
if r['nodeType'] = 'empty' then
return true;
@@ -275,8 +272,9 @@ public
NodeName;
ExtAttr;
ExtNodes;
Parent;
//Parent;
ReplaceArr;
RootObj;
NodeUri:string;
children_;
End
+34 -1
View File
@@ -158,6 +158,22 @@ Type TOffice = Class
return getChartImpl(p, true);
End;
///获取当前TSL代码段上一个文本框图
///[p]:可选参数,为Nil指当前段落
///返回:TTextBox对象
Function GetPrevTextBox(p);
Begin
p1 := getTextBoxImpl(p, false);
End;
///获取当前TSL代码段下一个文本框图
///[p]:可选参数,为Nil指当前段落
///返回:TTextBox对象
Function GetNextTextBox(p);
Begin
return getTextBoxImpl(p, true);
End;
Function Set(k, v);
Begin
hash_[k] := v;
@@ -214,5 +230,22 @@ private
return nil;
End;
Function getTextBoxImpl(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
p := TOfficeObj('TParagraph');
boxs := p.TextBoxs();
if istable(boxs) then Begin
if next then return boxs[0];
return boxs[ length(boxs) - 1];
End;
node := next ? p.node.NextElement('w:p') : p.node.PrevElement('w:p');
End;
return nil;
End;
hash_;
End;
End;
+1 -1
View File
@@ -261,7 +261,7 @@ Type TSXml = Class
class Function GetWorkSheetPrevNode(workNode, nodeName);
Begin
order_arr := array('dimension', 'sheetViews', 'sheetFormatPr', 'cols', 'sheetData', 'mergeCells', 'phoneticPr',
order_arr := array('dimension', 'sheetViews', 'sheetFormatPr', 'cols', 'sheetData', 'sheetProtection', 'mergeCells', 'phoneticPr',
'hyperlinks', 'pageMargins', 'headerFooter', 'pageSetup', 'rowBreaks', 'colBreaks', 'drawing', 'legacyDrawing', 'picture');
for i:=0 to length(order_arr)-1 do
begin
+1 -1
View File
@@ -38,7 +38,7 @@ Type TDocxStyles = Class
Function Default(styleType);
Begin
for k, obj in idMap_ do Begin
if obj.wType_ = styleType then Begin
if obj.wType = styleType then Begin
v := obj.node_.GetAttribute('w:default');
if v <> '1' then
return obj;
-1
View File
@@ -96,7 +96,6 @@ Type xlsxImage = Class
o.Pic.NvPicPr.NodeName := 'xdr:nvPicPr';
o.Pic.NvPicPr.CNvPr.Name := picture.Name ? picture.Name : '';
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';
o.Pic.NvPicPr.CNvPr.Replace(array("pic:": "xdr:"));
-7
View File
@@ -7,13 +7,6 @@ Type xlsxShape = Class
zipfile_ := excel.Zip();
drawing_id := excel_.WorkBook().GetSheetDrawing(sheetName_);
sheet_xml := excel_.WorkBook().GetSheetXmlfile(sheetName_);
node := sheet_xml.FirstChildElement('worksheet');
drawing_node := node.FirstChildElement('drawing');
if not ifObj(drawing_node) then
drawing_node := node.InsertEndChild('element', 'drawing');
drawing_node.SetAttribute('r:id', 'rId' $ drawing_id);
// drawingN.xml
drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawing_id $ ".xml");
End;
+8 -5
View File
@@ -15,6 +15,11 @@ Type xlsxSheetView = Class
id := sheet_view_node.GetAttribute('workbookViewId');
if trystrtoint(id, r) and r = viewIndex then
Begin
attributes := sheet_view_node.Attributes();
sheetView.TabSelected := attributes['tabselected'];
sheetView.WorkbookViewId := attributes['workbookViewId'];
sheetView.ZoomScaleNormal := ZoomScale;
for k, v in attributes do sheet_view_node.DeleteAttribute(k);
marshal := SheetView.Marshal();
class(TSXml).UpdateNode(sheet_view_node, marshal['attributes'], array());
return '';
@@ -32,15 +37,13 @@ Type xlsxSheetView = Class
id := sheet_view_node.GetAttribute('workbookViewId');
if trystrtoint(id, r) and r = viewIndex then
Begin
marshal := sheet_view_node.Marshal()[0];
sheetview := TOfficeObj('TSheetView');
sheetview.ShowGridLines := marshal['attributes']['showGridLines'];
sheetview.ShowRowColHeaders := marshal['attributes']['showRowColHeaders'];
sheetview.ZoomScale := marshal['attributes']['zoomScale'];
sheetview.ZoomScaleNormal := marshal['attributes']['zoomScaleNormal'];
sheetview.RootObj := sheet_view_node;
return sheetview;
End
sheet_view_node := sheet_view_node.NextElement();
End
return nil;
End
class Function NewObject(sheetname, file);
@@ -902,6 +902,25 @@ Type xlsxWorkBook = Class
end
End
Function ProtectSheet(sheet, protect);
Begin
sheet_obj := GetSheetXmlfile(sheet);
work_node := sheet_obj.FirstChildElement('worksheet');
sheet_protection_node := work_node.FirstChildElement('sheetProtection');
if ifObj(sheet_protection_node) then work_node.DeleteChild(sheet_protection_node);
prev_node := class(TSXml).GetWorkSheetPrevNode(work_node, 'sheetProtection');
protect.Sheet := 1;
work_node.InsertAfterChild(prev_node, protect.Marshal());
End;
Function UnProtectSheet(sheet);
Begin
sheet_obj := GetSheetXmlfile(sheet);
work_node := sheet_obj.FirstChildElement('worksheet');
sheet_protection_node := work_node.FirstChildElement('sheetProtection');
if ifObj(sheet_protection_node) then work_node.DeleteChild(sheet_protection_node);
End;
Function GetXmlFileObj(n);
Begin
o := xmlFileObjMap_[ n ];