This commit is contained in:
csh 2023-02-02 14:45:21 +08:00
parent 8276de4e92
commit bdf358b39b
12 changed files with 194 additions and 37 deletions

View File

@ -519,12 +519,15 @@ println("[success] ProtectSheet");
// SetDefaultFont // SetDefaultFont
font := tofficeobj('tfont'); font := tofficeobj('tfont');
font.name := '黑体'; font.Name := '黑体';
font.size := 13; font.Size := 13;
font.themecolor := 1; font.ThemeColor := 1;
excel.SetDefaultFont(font); excel.SetDefaultFont(font);
println("[success] SetDefaultFont"); println("[success] SetDefaultFont");
tfont := excel.GetDefaultFont();
println("[success] GetDefaultFont , name = {}, size = {}, themecolor = {}", tfont.Name, tfont.Size, tfont.ThemeColor);
[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.

View File

@ -1,5 +1,4 @@
// Version 1.1.3 Version 1.1.4
Function TOfficeObj(n); Function TOfficeObj(n);
Begin Begin
case lowercase(n) of case lowercase(n) of
@ -337,6 +336,136 @@ type TFont=class(NodeInfo)
RootObj := node; RootObj := node;
End; End;
Property Name read readXMLName write writeXMLName;
Function readXMLName();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Name'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLName);
End;
Function writeXMLName(str);
Begin
XMLName := class(TSXml).CurCodePageToUtf8(str);
End;
Property Size read readXMLSize write writeXMLSize;
Function readXMLSize();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Size'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLSize);
End;
Function writeXMLSize(str);
Begin
XMLSize := class(TSXml).CurCodePageToUtf8(str);
End;
Property Bold read readXMLBold write writeXMLBold;
Function readXMLBold();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Bold'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLBold);
End;
Function writeXMLBold(str);
Begin
XMLBold := class(TSXml).CurCodePageToUtf8(str);
End;
Property Italic read readXMLItalic write writeXMLItalic;
Function readXMLItalic();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Italic'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLItalic);
End;
Function writeXMLItalic(str);
Begin
XMLItalic := class(TSXml).CurCodePageToUtf8(str);
End;
Property Color read readXMLColor write writeXMLColor;
Function readXMLColor();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Color'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLColor);
End;
Function writeXMLColor(str);
Begin
XMLColor := class(TSXml).CurCodePageToUtf8(str);
End;
Property ThemeColor read readXMLThemeColor write writeXMLThemeColor;
Function readXMLThemeColor();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('ThemeColor'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLThemeColor);
End;
Function writeXMLThemeColor(str);
Begin
XMLThemeColor := class(TSXml).CurCodePageToUtf8(str);
End;
Property Strikethrough read readXMLStrikethrough write writeXMLStrikethrough;
Function readXMLStrikethrough();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Strikethrough'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLStrikethrough);
End;
Function writeXMLStrikethrough(str);
Begin
XMLStrikethrough := class(TSXml).CurCodePageToUtf8(str);
End;
Property Script read readXMLScript write writeXMLScript;
Function readXMLScript();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Script'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLScript);
End;
Function writeXMLScript(str);
Begin
XMLScript := class(TSXml).CurCodePageToUtf8(str);
End;
Property Charset read readXMLCharset write writeXMLCharset;
Function readXMLCharset();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Charset'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLCharset);
End;
Function writeXMLCharset(str);
Begin
XMLCharset := class(TSXml).CurCodePageToUtf8(str);
End;
Property Underline read readXMLUnderline write writeXMLUnderline;
Function readXMLUnderline();
Begin
tmpVal := class(TSXml).Utf8ToCurCodePage(Value('Underline'));
if not ifNil(tmpVal) then return tmpVal;
return class(TSXml).Utf8ToCurCodePage(XMLUnderline);
End;
Function writeXMLUnderline(str);
Begin
XMLUnderline := class(TSXml).CurCodePageToUtf8(str);
End;
Function GetAttrs(); override; Function GetAttrs(); override;
Begin Begin
HandleAttrs(); HandleAttrs();
@ -346,16 +475,16 @@ type TFont=class(NodeInfo)
Function GetChildren(); override; Function GetChildren(); override;
Begin Begin
HandleChildren(); HandleChildren();
return array(("field":"FontName","name":"name","obj":FontName,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") return array(("field":"Name","name":"name","obj":XMLName,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Size","name":"sz","obj":Size,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"Size","name":"sz","obj":XMLSize,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Bold","name":"b","obj":Bold,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"") ,("field":"Bold","name":"b","obj":XMLBold,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"")
,("field":"Italic","name":"i","obj":Italic,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"") ,("field":"Italic","name":"i","obj":XMLItalic,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"")
,("field":"Color","name":"color","obj":Color,"attrEx":"","nodeType":"","attrName":"rgb", "desc":"", "class":"") ,("field":"Color","name":"color","obj":XMLColor,"attrEx":"","nodeType":"","attrName":"rgb", "desc":"", "class":"")
,("field":"ThemeColor","name":"color","obj":ThemeColor,"attrEx":"theme","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"ThemeColor","name":"color","obj":XMLThemeColor,"attrEx":"theme","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Strikethrough","name":"strike","obj":Strikethrough,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"") ,("field":"Strikethrough","name":"strike","obj":XMLStrikethrough,"attrEx":"","nodeType":"empty","attrName":"", "desc":"", "class":"")
,("field":"Script","name":"vertAlign","obj":Script,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"Script","name":"vertAlign","obj":XMLScript,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Charset","name":"charset","obj":Charset,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"Charset","name":"charset","obj":XMLCharset,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Underline","name":"u","obj":Underline,"attrEx":"","nodeType":"empty_string","attrName":"", "desc":"", "class":"") ,("field":"Underline","name":"u","obj":XMLUnderline,"attrEx":"","nodeType":"empty_string","attrName":"", "desc":"", "class":"")
,("field":"FontStyle","name":"fontstyle","obj":FontStyle,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"FontStyle","name":"fontstyle","obj":FontStyle,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"OutlineFont","name":"outlinefont","obj":OutlineFont,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"OutlineFont","name":"outlinefont","obj":OutlineFont,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
,("field":"Shadow","name":"shadow","obj":Shadow,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"") ,("field":"Shadow","name":"shadow","obj":Shadow,"attrEx":"","nodeType":"","attrName":"", "desc":"", "class":"")
@ -369,26 +498,19 @@ type TFont=class(NodeInfo)
) union ExtNodes; ) union ExtNodes;
End; End;
Property Name write writeName;
Function writeName(n);
Begin
nName := class(TSXml).CurCodePageToUtf8(n);
FontName := nName;
End;
//Attributes //Attributes
//Nodes //Nodes
FontName; XMLName;
Size; XMLSize;
Bold; XMLBold;
Italic; XMLItalic;
Color; XMLColor;
ThemeColor; XMLThemeColor;
Strikethrough; XMLStrikethrough;
Script; XMLScript;
Charset; XMLCharset;
Underline; XMLUnderline;
FontStyle; FontStyle;
OutlineFont; OutlineFont;
Shadow; Shadow;
@ -14176,3 +14298,5 @@ private
middlePosition; middlePosition;
End End

View File

@ -1,5 +1,4 @@
// Version 1.1.3 Version 1.1.4
Type TSDocxFile = Class Type TSDocxFile = Class
///Version: V1.0 2022-09-20 ///Version: V1.0 2022-09-20
///适用于 Microsoft Word docx格式文件 ///适用于 Microsoft Word docx格式文件
@ -466,3 +465,4 @@ private
numberingObj_; numberingObj_;
DocPrId_; DocPrId_;
End; End;

View File

@ -1,5 +1,4 @@
// Version 1.1.3 Version 1.1.4
Type TSExcelFile = Class Type TSExcelFile = Class
///Version: V1.0 2022-08-08 ///Version: V1.0 2022-08-08
///适用于 Microsoft Excel? 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式。 ///适用于 Microsoft Excel? 2007 及以上版本创建的电子表格文档。支持 XLSX / XLSM / XLTM / XLTX 等多种文档格式。
@ -839,6 +838,13 @@ Type TSExcelFile = Class
return workbook_.SetDefaultFont(font); return workbook_.SetDefaultFont(font);
End; End;
///获取默认字体
///返回: TFont对象
Function GetDefaultFont();
Begin
return workbook_.GetDefaultFont();
End;
Function WorkBook(); Function WorkBook();
Begin Begin
return workbook_; return workbook_;
@ -893,3 +899,4 @@ private
workbook_; //WorkBook对象 workbook_; //WorkBook对象
objMgr_; //各种对象缓存、管理 objMgr_; //各种对象缓存、管理
End; End;

View File

@ -209,7 +209,7 @@ Type TNumbering = Class
Function _setNsId(o); Function _setNsId(o);
Begin Begin
v := Integer(RandomRange(1000000000,2000000000)); v := Integer(RandomRange(1000000000,2000000000));
id := inttohex(v); id := inttohex(v, 1);
if hash_[id] then if hash_[id] then
return _setNsId(o); return _setNsId(o);
hash_[id] := 1; hash_[id] := 1;

View File

@ -1133,6 +1133,16 @@ Type xlsxWorkBook = Class
fonts_node.InsertFirstChild(font.Marshal()); fonts_node.InsertFirstChild(font.Marshal());
End; End;
Function GetDefaultFont();
Begin
style_xml := GetXmlFileObj('xl/styles.xml');
fonts_node := style_xml.FirstChildElement('styleSheet').FirstChildElement('fonts');
first_node := fonts_node.FirstChildElement('font');
tfont := TOfficeObj('TFont');
tfont.RootObj := first_node;
return tfont;
End;
private private
Function generateRow(c1, c2, r); Function generateRow(c1, c2, r);
Begin Begin

View File

@ -1,5 +1,18 @@
# 更新日志 # 更新日志
## 2023-2-2
### V1.1.4
#### word
1. 修复文本框插入图片兼容性问题
2. 修复项目符号问题
#### excel
1. 新增`GetDefaultFont`
## 2023-2-1 ## 2023-2-1
### V1.1.3 ### V1.1.3