This commit is contained in:
csh
2023-04-18 15:34:45 +08:00
parent df79a459dd
commit 77762ce275
9 changed files with 244 additions and 243 deletions
+90 -35
View File
@@ -6,7 +6,7 @@ sheetName2 := "中文";
// OpenFile
excel := new TSExcelFile();
[err, errmsg] := excel.OpenFile('', 'd:\\temp\\raw.xlsx');
[err, errmsg] := excel.OpenFile('', 'd:\\temp\\b.xlsx');
PrintInfo("OpenFile", err, errmsg);
// Save
@@ -14,14 +14,13 @@ PrintInfo("OpenFile", err, errmsg);
PrintInfo("Save", err, errmsg);
excel := new TSExcelFile();
// NewFile
[err, errmsg] := excel.NewFile();
PrintInfo("NewFile", err, errmsg);
// SaveAs
// [err, errmsg] := excel.SaveAs('', 'd:\\temp\\test.xlsx');
// PrintInfo("SaveAs", err, errmsg);
[err, errmsg] := excel.SaveAs('', 'd:\\temp\\test.xlsx');
PrintInfo("SaveAs", err, errmsg);
// FileName
name := excel.FileName();
@@ -43,6 +42,14 @@ println("[success] GetSheetName = {}", Name);
excel.NewSheet(sheetName2);
println("[success] NewSheet");
// NewSheet
excel.NewSheet(sheetName, 'sheet_copy');
println("[success] NewSheet2");
// InsertSheet
excel.InsertSheet(sheetName, sheetName + 'before');
println("[success] NewSheet2");
// GetSheets
sheets := excel.GetSheets();
println("[success] sheets = {}", sheets);
@@ -93,7 +100,7 @@ excel.ClearCell(sheetName, "A1");
println("[success] ClearCell");
// SetCellFormula
excel.SetCellFormula(sheetName, "A2", "=100*50");
excel.SetCellFormula(sheetName, "A2", "100*50");
println("[success] SetCellFormula");
// GetCellFormula
@@ -134,13 +141,13 @@ println("[success] RemoveRow");
// SetRowHeight
excel.SetRowHeight(sheetName, 1, 30);
excel.SetRowHeight(sheetName, 15, 30);
excel.SetRowHeight(sheetName, 5, 30);
println("[success] SetRowHeight");
// GetRowHeight
height := excel.GetRowHeight(sheetName, 2);
println("[success] GetRowHeight = {}", height);
height := excel.GetRowHeight(sheetName, 15);
height := excel.GetRowHeight(sheetName, 5);
println("[success] GetRowHeight = {}", height);
// SetColWidth
@@ -165,6 +172,9 @@ println("[success] GetSheetDefaultColWidth = {}", width);
excel.AddComment(sheetName, "A1", "csh", "heiheihei");
println("[success] AddComment");
[author, comment] := excel.GetComment(sheetName, 'A1');
println("[success] GetComment author = {}, comment = {}", author, comment);
// AddChart
data := array(("Name":"Small","Apple":2,"Orange":3,"Pear":3),
("Name":"Normal","Apple":5,"Orange":2,"Pear":4),
@@ -219,6 +229,12 @@ PrintInfo("ColumnNumberToName", err, errmsg);
[err, col, row] := excel.CellNameToCoordinates("A2");
if not err then println("[success] {} = col : {}, row = {}", "CellNameToCoordinates", col, row);
// CoordinatesToCellName
[err, cell] := excel.CoordinatesToCellName(1, 2, true);
println("[success] CoordinatesToCellName, cell = {}", cell);
[err, cell] := excel.CoordinatesToCellName(1, 2);
println("[success] CoordinatesToCellName, cell = {}", cell);
// RGBToHSL
[h, s, l] := excel.RGBToHSL(255, 15, 33);
println("[success] {} = {}, {}, {}", "RGBToHSL", h, s, l);
@@ -259,9 +275,11 @@ style.NumberFormat.FormatCode := "#,##0.000_ ";
//style.Fill.Pattern.PatternType := "solid";
//style.Fill.Pattern.ForegroundColor := "FF6699FF";
//style.Fill.Pattern.BackgroundColor := "FFFF0000";
style.Fill.Gradient.ThemeColor1 := 0;
style.Fill.Gradient.ThemeColor2 := 4;
style.Fill.Gradient.Shading := 1;
style.Fill.Gradient.Degree := 270;
style.Fill.Gradient.Stop1.Position := 0;
style.Fill.Gradient.Stop1.ThemeColor := 0;
style.Fill.Gradient.Stop2.Position := 1;
style.Fill.Gradient.Stop2.ThemeColor := 4;
style.Protection.Hide := 1;
style.Protection.Lock := 1;
@@ -274,8 +292,23 @@ println("[success] SetCellStyle");
styleid := excel.GetCellStyle(sheetName, "A1");
println("[success] GetCellStyle = {}", styleid);
styleid := excel.GetCellStyle(sheetName, "D4");
println("[success] GetCellStyle = {}", styleid);
style := excel.GetStyle(styleid);
println("font.Name = {}", style.Font.Name);
println("font.Italic = {}", style.Font.Italic);
println("border.left.Color = {}", style.border.left.Color);
println("border.Top.LineStyle = {}", style.border.Top.LineStyle);
println("border.DiagonalDown = {}", style.border.DiagonalDown);
println("numberFormat.FormatCode = {}", style.NumberFormat.FormatCode);
println("alignment.vertical = {}", style.Alignment.Vertical);
println("alignment.TextRotation = {}", style.Alignment.TextRotation);
println("protection.Hide = {}", style.Protection.Hide);
println("protection.Lock = {}", style.Protection.Lock);
//println("fill.pattern.PatternType = {}", style.Fill.Pattern.PatternType);
//println("fill.pattern.ForegroundColor = {}", style.Fill.Pattern.ForegroundColor);
println("style.Fill.Gradient.Degree = {}", style.Fill.Gradient.Degree);
println("style.Fill.Gradient.Stop1.ThemeColor = {}", style.Fill.Gradient.Stop1.ThemeColor);
println("style.Fill.Gradient.Stop2.Position = {}", style.Fill.Gradient.Stop2.Position);
// SetSheetHeaderFooter
headerFooter := TOfficeObj("THeaderFooter");
@@ -290,7 +323,6 @@ headerFooter.EvenFooter := "&L456&R789";
headerFooter.FirstHeader := "&L++";
headerFooter.FirstFooter := "&R--";
excel.SetSheetHeaderFooter(sheetName, headerFooter);
println("[success] SetSheetHeaderFooter");
// SetSheetVisible
excel.SetSheetVisible(sheetName, True);
@@ -332,8 +364,8 @@ println("[success] SetPageMargins");
// GetPageMargins
margins := excel.GetPageMargins(sheetName2);
println("[success] GetPageMargins top = {}, bottom = {}, left = {}, right = {}, header = {}, footer = {}",
margins.Value('Top'), margins.Value('Bottom'), margins.Value('Left'), margins.Value('Right'),
margins.Value('Header'), margins.Value('Footer'));
margins.Top, margins.Bottom, margins.Left, margins.Right,
margins.Header, margins.Footer);
// MergeCell
excel.SetCellStyle(sheetName2, "A4", "A4", styleid1);
@@ -345,6 +377,7 @@ println("[success] MergeCell");
excel.UnMergeCell(sheetName2, "A4", "C4");
println("[success] UnMergeCell");
// SetSheetViewOptions
sheetView := TOfficeObj('TSheetView');
sheetView.ShowGridLines := false;
@@ -372,6 +405,7 @@ println("[success] SetPane");
pageLayout := TOfficeObj('TPageLayout');
pageLayout.FitToWidth := 10;
pageLayout.FitToHeight := 10;
pageLayout.UseFirstPageNumber := true;
pageLayout.FirstPageNumber := 5;
pageLayout.Orientation := "portrait";
pageLayout.BlackAndWhite := true;
@@ -412,9 +446,10 @@ hyperlink := excel.GetCellHyperLink(sheetName2, 'A2');
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);
imagepath := "C:\\Users\\csh05\\Pictures\\1png.png";
ret := readfile(rwBinary(), "", imagepath, 0, 1024000, data);
if not ret then return echo "readfile error!";
picture := TOfficeObj('TPicture');
Image := TOfficeObj('TPicture');
picture.Image := data;
excel.SetSheetBackground(sheetName, picture);
println("[success] SetSheetBackground");
@@ -528,30 +563,50 @@ println("[success] SetDefaultFont");
tfont := excel.GetDefaultFont();
println("[success] GetDefaultFont , name = {}, size = {}, themecolor = {}", tfont.Name, tfont.Size, tfont.ThemeColor);
calcpr := TOfficeObj('TCalcPr');
calcpr.CalcMode := "";
calcpr.RefMode := "R1C1";
calcpr.Iterate := 1;
calcpr.IterateCount := 300;
calcpr.IterateDelta := "3E-3";
calcpr.CalcOnSave := true;
calcpr.ConCurrentCalc := true;
calcpr.ConCurrentManualCount := 4;
calcpr.FullPrecision := 0;
excel.SetCalcOptions(calcpr);
println("[success] SetCalcOptions");
calc := excel.GetCalcOptions();
println("[success] GetCalcOptions, CalcMode = {}, RefMode = {}, Iterate = {},
IterateCount = {}, IterateDelta = {}, CalcOnSave = {}, conCurrentCalc = {},
conCurrentManualCount = {}, FullPrecision = {}", calc.CalcMode, calc.RefMode, calc.Iterate,
calc.IterateCount, calc.IterateDelta, calc.CalcOnSave, calc.conCurrentCalc,
calc.conCurrentManualCount, calc.FullPrecision);
excel.SetRowOutlineLevel(sheetName2, 1, 1);
excel.SetRowOutlineLevel(sheetName2, 2, 1);
println("[success] SetRowOutlineLevel");
level1 := excel.GetRowOutlineLevel(sheetName2, 1);
level2 := excel.GetRowOutlineLevel(sheetName2, 3);
println("[success] GetRowOutlineLevel, level1 = {}, level2 = {}", level1, level2);
excel.SetColOutlineLevel(sheetName2, 'A', 1);
excel.SetColOutlineLevel(sheetName2, 'B', 2);
excel.SetColOutlineLevel(sheetName2, 'C', 1);
println("[success] SetColOutlineLevel");
level1 := excel.GetColOutlineLevel(sheetName2, 'A');
level2 := excel.GetColOutlineLevel(sheetName2, 'B');
println("[success] GetColOutlineLevel, level1 = {}, level2 = {}", level1, level2);
[err, errmsg] := excel.saveas("", "d:\\temp\\test.xlsx");
println("saveas : {}", err);
Function _test_background(excel);
Begin
f := 'D:\\temp\\a.xlsx';
[err, msg] := excel.OpenFile('', f);
if err then return
echo "Open Fail:", msg, '\n';
ret := readfile(rwBinary(), "", "C:\\Users\\csh05\\Pictures\\Saved Pictures\\1.png", 0, 102400, data);
if ret then pictrue := new TSImage(data);
else return echo "readfile error!";
excel.SetSheetBackground('Sheet1', pictrue);
[err, errmsg] := excel.SaveAs('', 'd:\\temp\\e.xlsx');
println('SaveAs->{}',err);
End
// ============================================================
Function PrintInfo(msg, err, errinfo);
Begin
if err then debugreturn println("{} : errorno = {}, errorinfo = {}!", msg, err, errinfo);
println("[success] {} = {}", msg, errinfo);
End