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
+30
View File
@@ -717,5 +717,35 @@ style.Protection.Lock := 1;
), ),
'Demo': '', 'Demo': '',
), ),
('ObjName': 'TProtect',
'Desc': ('TProtect有以下属性: '),
'AttrInfo': (
('attrName': 'EditObjects', 'type': 'bool', 'desc': '编辑方案', 'value': array()),
('attrName': 'EditScenarios', 'type': 'bool', 'desc': '编辑方案', 'value': array()),
('attrName': 'FormatCells', 'type': 'bool', 'desc': '设置单元格格式', 'value': array()),
('attrName': 'FormatColumns', 'type': 'bool', 'desc': '设置列格式', 'value': array()),
('attrName': 'FormatRows', 'type': 'bool', 'desc': '设置行格式', 'value': array()),
('attrName': 'InsertColumns', 'type': 'bool', 'desc': '插入行', 'value': array()),
('attrName': 'InsertRows', 'type': 'bool', 'desc': '插入列', 'value': array()),
('attrName': 'InsertHyperlinks', 'type': 'bool', 'desc': '插入超链接', 'value': array()),
('attrName': 'DeleteColumns', 'type': 'bool', 'desc': '删除列', 'value': array()),
('attrName': 'DeleteRows', 'type': 'bool', 'desc': '删除行', 'value': array()),
('attrName': 'SelectLockedCells', 'type': 'bool', 'desc': '选定锁定的单元格', 'value': array()),
('attrName': 'Sort', 'type': 'bool', 'desc': '排序', 'value': array()),
('attrName': 'AutoFilter', 'type': 'bool', 'desc': '使用自动筛选', 'value': array()),
('attrName': 'PivotTables', 'type': 'bool', 'desc': '使用自动透视表和自动透视图', 'value': array()),
),
'Demo': '',
),
('ObjName': 'TSheetView',
'Desc': ('TSheetView有以下属性: '),
'AttrInfo': (
('attrName': 'ShowGridLines', 'type': 'bool', 'desc': '网格线', 'value': array()),
('attrName': 'ShowRowColHeaders', 'type': 'bool', 'desc': '标题', 'value': array()),
('attrName': 'View', 'type': 'string', 'desc': '工作簿视图', 'value': array('"pageBreakPreview": 分页预览')),
('attrName': 'ZoomScale', 'type': 'bool', 'desc': '缩放比例(%)', 'value': array()),
),
'Demo': '',
),
); );
End End
+36 -3
View File
@@ -344,9 +344,18 @@ println("[success] MergeCell");
excel.UnMergeCell(sheetName2, "A4", "C4"); excel.UnMergeCell(sheetName2, "A4", "C4");
println("[success] UnMergeCell"); println("[success] UnMergeCell");
// TODO 未完全开发完毕
// SetSheetViewOptions // SetSheetViewOptions
sheetView := TOfficeObj('TSheetView');
sheetView.ShowGridLines := false;
sheetView.ShowRowColHeaders := false;
sheetView.View := 'pageBreakPreview';
sheetView.ZoomScale := 60;
excel.SetSheetViewOptions(sheetName, 0, sheetView);
println("[success] SetSheetViewOptions");
// GetSheetViewOptions // GetSheetViewOptions
view := excel.GetSheetViewOptions(sheetName, 0);
println("[success] GetSheetViewOptions ShowGridLines = {}, ShowRowColHeaders = {}, View = {}, ZoomScale = {}", view.ShowGridLines, view.ShowRowColHeaders, view.ZoomScale, view.View);
// SetPageLayout // SetPageLayout
pageLayout := TOfficeObj('TPageLayout'); pageLayout := TOfficeObj('TPageLayout');
@@ -441,8 +450,8 @@ shape_format.EndColOff := 7653;
shape_format.BegRowOff := 55577; shape_format.BegRowOff := 55577;
shape_format.EndRowOff := 66675; shape_format.EndRowOff := 66675;
shape_type := "roundRect"; shape_type := "roundRect";
//excel.AddShape(sheetName2, "A15", "C17", shape_type, shape_format); excel.AddShape(sheetName2, "A15", "C17", shape_type, shape_format);
//println("[success] AddShape"); println("[success] AddShape");
// SetCoreProps // SetCoreProps
core := TOfficeObj('TCoreProperty'); core := TOfficeObj('TCoreProperty');
@@ -473,6 +482,30 @@ println("[success] SetAppProps");
app_props := excel.GetAppProps(); app_props := excel.GetAppProps();
println("[success] GetAppProps Manager = {}, Company = {}, Application = {}", app_props.Manager, app_props.Company, app_props.Application); println("[success] GetAppProps Manager = {}, Company = {}, Application = {}", app_props.Manager, app_props.Company, app_props.Application);
// CopySheet
excel.CopySheet(sheetName2, 'copy');
println("[success] CopySheet");
// ProtectSheet
protect := TOfficeObj('TProtect');
protect.EditObjects := true;
protect.EditScenarios := true;
protect.FormatCells := true;
protect.FormatColumns := true;
protect.FormatRows := true;
protect.InsertColumns := true;
protect.InsertRows := true;
protect.InsertHyperlinks := true;
protect.DeleteColumns := true;
protect.DeleteRows := true;
protect.Sort := true;
protect.AutoFilter := true;
protect.PivotTables := true;
protect.SelectLockedCells := true;
protect.SelectUnLockedCells := true;
excel.ProtectSheet(sheetName2, protect);
println("[success] ProtectSheet");
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx"); [err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
println("saveas : {}", err); println("saveas : {}", err);
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
+2 -2
View File
@@ -1,4 +1,4 @@
// Version 1.1.0 // Version 1.1.1
Type TSDocxFile = Class Type TSDocxFile = Class
///Version: V1.0 2022-09-20 ///Version: V1.0 2022-09-20
@@ -260,7 +260,7 @@ Type TSDocxFile = Class
Function GetCharts();overload; Function GetCharts();overload;
Begin Begin
r := array(); 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(); ps := Paragraphs();
for i:=0 to length(ps)-1 do Begin for i:=0 to length(ps)-1 do Begin
node := class(TSXml).GetNode(ps[i].node_, uri); 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 Type TSExcelFile = Class
///Version: V1.0 2022-08-08 ///Version: V1.0 2022-08-08
@@ -615,7 +615,7 @@ Type TSExcelFile = Class
///设置工作表视图属性 ///设置工作表视图属性
///sheet: string,工作表名称 ///sheet: string,工作表名称
///viewIndex: int,视图索引 ///viewindex: int,视图索引viewIndex,从0开始
///sheet: objectTSheetView对象 ///sheet: objectTSheetView对象
Function SetSheetViewOptions(sheet, viewIndex, sheetView); Function SetSheetViewOptions(sheet, viewIndex, sheetView);
Begin Begin
@@ -625,7 +625,6 @@ Type TSExcelFile = Class
///获取工作表视图属性 ///获取工作表视图属性
///sheet: string,工作表名称 ///sheet: string,工作表名称
///viewindex: int,视图索引,viewIndex 可以是负数,如果是这样,则向后计数(-1 代表最后一个视图)
///返回: object, TSheetView对象 ///返回: object, TSheetView对象
Function GetSheetViewOptions(sheet, viewIndex); Function GetSheetViewOptions(sheet, viewIndex);
Begin Begin
@@ -634,7 +633,7 @@ Type TSExcelFile = Class
End; End;
// TODO printerSettings1.bin? // TODO printerSettings1.bin?
///设置工作表页面设置 ///设置工作表页面布局
///sheet: string,工作表名称 ///sheet: string,工作表名称
///pageLayout: TPageLayout对象,属性: ///pageLayout: TPageLayout对象,属性:
Function SetPageLayout(sheet, pageLayout); Function SetPageLayout(sheet, pageLayout);
@@ -643,7 +642,7 @@ Type TSExcelFile = Class
if ifObj(o) then return o.SetPageLayout(class(TSXml).CurCodePageToUtf8(sheet), pageLayout); if ifObj(o) then return o.SetPageLayout(class(TSXml).CurCodePageToUtf8(sheet), pageLayout);
End; End;
///获取工作表页面设置 ///获取工作表页面布局
///sheet: string,工作表名称 ///sheet: string,工作表名称
///返回: TPageLayout对象 ///返回: TPageLayout对象
Function GetPageLayout(sheet); Function GetPageLayout(sheet);
@@ -799,6 +798,21 @@ Type TSExcelFile = Class
return workbook_.CopySheet(class(TSXml).CurCodePageToUtf8(sourceSheet), class(TSXml).CurCodePageToUtf8(destSheet)); return workbook_.CopySheet(class(TSXml).CurCodePageToUtf8(sourceSheet), class(TSXml).CurCodePageToUtf8(destSheet));
End; 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(); Function WorkBook();
Begin Begin
return workbook_; return workbook_;
+17 -19
View File
@@ -3,7 +3,10 @@ Type NodeInfo = class
public public
Function Create(p, name); Function Create(p, name);
Begin Begin
Parent := p; if ifObj(p) then
NodeUri := p.NodeUri = '' ? name : (p.NodeUri + '/' + name);
else
NodeUri := '';
NodeName := name; NodeName := name;
ExtAttr := array(); ExtAttr := array();
ExtNodes := array(); ExtNodes := array();
@@ -20,7 +23,9 @@ 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(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; End;
End; End;
@@ -152,32 +157,24 @@ public
Function Value(name); Function Value(name);
Begin Begin
uri := ifObj(Parent) ? NodeName : ''; if not ifObj(RootObj) then return nil;
p := Parent; if NodeUri <> '' then
rootNode := Root(); node := class(TSXml).GetNode(RootObj, NodeUri);
while ifObj(p) do Begin else
if ifObj(p.Parent) then node := RootObj;
uri := p.NodeName + (uri ? '/' : '') + uri; if not ifObj(node) then return nil;
rootNode := p.Root();
p := p.Parent;
End;
if not ifObj(rootNode) then return nil;
attrs := GetAttrsEx(); attrs := GetAttrsEx();
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
node := class(TSXml).GetNode(rootNode, uri);
if not ifObj(node) then return nil;
return node.GetAttribute(r[1]); return node.GetAttribute(r[1]);
End;
children := GetChildren(); children := GetChildren();
r := select * from children where lName = lowerCase(['field']) end; r := select * from children where lName = lowerCase(['field']) end;
if istable(r) then Begin if istable(r) then Begin
r := r[0]; r := r[0];
uri := (uri='' ? '' : uri + '/') + r['name']; node := node.FirstChildElement(r['name']);
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;
@@ -275,8 +272,9 @@ public
NodeName; NodeName;
ExtAttr; ExtAttr;
ExtNodes; ExtNodes;
Parent; //Parent;
ReplaceArr; ReplaceArr;
RootObj; RootObj;
NodeUri:string;
children_; children_;
End End
+34 -1
View File
@@ -158,6 +158,22 @@ Type TOffice = Class
return getChartImpl(p, true); return getChartImpl(p, true);
End; 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); Function Set(k, v);
Begin Begin
hash_[k] := v; hash_[k] := v;
@@ -214,5 +230,22 @@ private
return nil; return nil;
End; 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_; hash_;
End; End;
+1 -1
View File
@@ -261,7 +261,7 @@ Type TSXml = Class
class Function GetWorkSheetPrevNode(workNode, nodeName); class Function GetWorkSheetPrevNode(workNode, nodeName);
Begin 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'); 'hyperlinks', 'pageMargins', 'headerFooter', 'pageSetup', 'rowBreaks', 'colBreaks', 'drawing', 'legacyDrawing', 'picture');
for i:=0 to length(order_arr)-1 do for i:=0 to length(order_arr)-1 do
begin begin
+1 -1
View File
@@ -38,7 +38,7 @@ Type TDocxStyles = Class
Function Default(styleType); Function Default(styleType);
Begin Begin
for k, obj in idMap_ do 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'); v := obj.node_.GetAttribute('w:default');
if v <> '1' then if v <> '1' then
return obj; return obj;
-1
View File
@@ -96,7 +96,6 @@ Type xlsxImage = Class
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(TSXml).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.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';
o.Pic.NvPicPr.CNvPr.Replace(array("pic:": "xdr:")); o.Pic.NvPicPr.CNvPr.Replace(array("pic:": "xdr:"));
-7
View File
@@ -7,13 +7,6 @@ Type xlsxShape = Class
zipfile_ := excel.Zip(); zipfile_ := excel.Zip();
drawing_id := excel_.WorkBook().GetSheetDrawing(sheetName_); 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 // drawingN.xml
drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawing_id $ ".xml"); drawingXmlObj_ := excel_.WorkBook().GetXmlFileObj('xl/drawings/drawing' $ drawing_id $ ".xml");
End; End;
+8 -5
View File
@@ -15,6 +15,11 @@ Type xlsxSheetView = Class
id := sheet_view_node.GetAttribute('workbookViewId'); id := sheet_view_node.GetAttribute('workbookViewId');
if trystrtoint(id, r) and r = viewIndex then if trystrtoint(id, r) and r = viewIndex then
Begin 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(); marshal := SheetView.Marshal();
class(TSXml).UpdateNode(sheet_view_node, marshal['attributes'], array()); class(TSXml).UpdateNode(sheet_view_node, marshal['attributes'], array());
return ''; return '';
@@ -32,15 +37,13 @@ Type xlsxSheetView = Class
id := sheet_view_node.GetAttribute('workbookViewId'); id := sheet_view_node.GetAttribute('workbookViewId');
if trystrtoint(id, r) and r = viewIndex then if trystrtoint(id, r) and r = viewIndex then
Begin Begin
marshal := sheet_view_node.Marshal()[0];
sheetview := TOfficeObj('TSheetView'); sheetview := TOfficeObj('TSheetView');
sheetview.ShowGridLines := marshal['attributes']['showGridLines']; sheetview.RootObj := sheet_view_node;
sheetview.ShowRowColHeaders := marshal['attributes']['showRowColHeaders'];
sheetview.ZoomScale := marshal['attributes']['zoomScale'];
sheetview.ZoomScaleNormal := marshal['attributes']['zoomScaleNormal'];
return sheetview; return sheetview;
End End
sheet_view_node := sheet_view_node.NextElement();
End End
return nil;
End End
class Function NewObject(sheetname, file); class Function NewObject(sheetname, file);
@@ -902,6 +902,25 @@ Type xlsxWorkBook = Class
end end
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); Function GetXmlFileObj(n);
Begin Begin
o := xmlFileObjMap_[ n ]; o := xmlFileObjMap_[ n ];
+16
View File
@@ -1,5 +1,21 @@
# 更新日志 # 更新日志
## 2023-1-18
### V1.1.1
#### word
1. 兼容文本框`TextBox`
2. 修正`TParagraph::TabStops`
3. 修复获取图标列表失败问题
4. 修复`TDocxStyles::Default`
#### excel
1. 新增`ProtectSheet``UnProtectSheet`
2. 修复`SetSheetViewOptions``GetSheetViewOptions`
## 2023-1-16 ## 2023-1-16
### V1.1.0 ### V1.1.0