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

View File

@ -717,5 +717,35 @@ style.Protection.Lock := 1;
),
'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

View File

@ -344,9 +344,18 @@ println("[success] MergeCell");
excel.UnMergeCell(sheetName2, "A4", "C4");
println("[success] UnMergeCell");
// TODO 未完全开发完毕
// 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
view := excel.GetSheetViewOptions(sheetName, 0);
println("[success] GetSheetViewOptions ShowGridLines = {}, ShowRowColHeaders = {}, View = {}, ZoomScale = {}", view.ShowGridLines, view.ShowRowColHeaders, view.ZoomScale, view.View);
// SetPageLayout
pageLayout := TOfficeObj('TPageLayout');
@ -441,8 +450,8 @@ shape_format.EndColOff := 7653;
shape_format.BegRowOff := 55577;
shape_format.EndRowOff := 66675;
shape_type := "roundRect";
//excel.AddShape(sheetName2, "A15", "C17", shape_type, shape_format);
//println("[success] AddShape");
excel.AddShape(sheetName2, "A15", "C17", shape_type, shape_format);
println("[success] AddShape");
// SetCoreProps
core := TOfficeObj('TCoreProperty');
@ -473,6 +482,30 @@ println("[success] SetAppProps");
app_props := excel.GetAppProps();
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");
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

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);

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_;

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

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;

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

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;

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:"));

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;

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);

View 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 ];

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
### V1.1.0