使用C#学习Office文件的处理(pptx docx xlsx)

Office文件 是指PPT 、word、Excel 这些常用工具生成的文件 ,例如 pptx docx xlsx。

这些文件的读取和生成有很多很多库 例如 NOPI 、DevExpress、C1、Aspose、Teleric 等等,各有各的优缺点。俺今天不讲这个,俺只是讲讲如何了解Office文件的格式。

说起Office文件,就绕不开微软,说起微软的Office文件 就不得不提及

这是微软给的Office的SDK,在对一些复杂文件的处理上特别有用,俺有一次处理一批复杂的文档,这批文档里有大量的数学公式,例如

这个公式,文档中存储的是数据流不是图片,俺用了很多第三方的都不行(DevExpress 应该可以,但是要购买贵的那个版本,俺看到版本说明里有支持,但是俺之前买的版本不是这个),所以用了微软的DocumentFormat.OpenXml.dll。

Open XML SDK 有2个很强大的功能,一个是结构化解析文档,另一个是逆向出C#源码

先看一个例子:

然后用Open XML SDK 打开这个文件

左边是文档结构,右边就是逆向出的C#代码。也是一种反编译了。

在VS里执行右边的代码就可以生成出完全一样的Office文件。

ppt word 文件也可以同样处理。

俺前面说的读那个公式,也是用这个SDK 逆向了一下文件,然后就知道如何提取那些特殊数据了。

如果对这个逆向工具感兴趣,还可以直接到微软去下载这个SDK的源码,这个逆向,微软提供了源码。

private void GenerateWorksheetPart12Content(WorksheetPart worksheetPart12)

{

Worksheet worksheet12 = new Worksheet(){ MCAttributes = new MarkupCompatibilityAttributes(){ Ignorable = "x14ac xr xr2 xr3" } };

worksheet12.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");

worksheet12.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");

worksheet12.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac");

worksheet12.AddNamespaceDeclaration("xr", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision");

worksheet12.AddNamespaceDeclaration("xr2", "http://schemas.microsoft.com/office/spreadsheetml/2015/revision2");

worksheet12.AddNamespaceDeclaration("xr3", "http://schemas.microsoft.com/office/spreadsheetml/2016/revision3");

worksheet12.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0001-0000-0200-000000000000}"));

SheetProperties sheetProperties11 = new SheetProperties(){ CodeName = "Sheet3" };

TabColor tabColor11 = new TabColor(){ Theme = (UInt32Value)9U, Tint = 0.59999389629810485D };

PageSetupProperties pageSetupProperties11 = new PageSetupProperties(){ FitToPage = true };

sheetProperties11.Append(tabColor11);

sheetProperties11.Append(pageSetupProperties11);

SheetDimension sheetDimension12 = new SheetDimension(){ Reference = "A1:I15" };

SheetViews sheetViews12 = new SheetViews();

SheetView sheetView12 = new SheetView(){ ShowGridLines = false, ShowRowColHeaders = false, ZoomScaleNormal = (UInt32Value)100U, WorkbookViewId = (UInt32Value)0U };

sheetViews12.Append(sheetView12);

SheetFormatProperties sheetFormatProperties12 = new SheetFormatProperties(){ DefaultColumnWidth = 8.75D, DefaultRowHeight = 13.5D, DyDescent = 0.25D };

Columns columns12 = new Columns();

Column column54 = new Column(){ Min = (UInt32Value)1U, Max = (UInt32Value)1U, Width = 1.58203125D, Style = (UInt32Value)1U, CustomWidth = true };

Column column55 = new Column(){ Min = (UInt32Value)2U, Max = (UInt32Value)8U, Width = 16.58203125D, Style = (UInt32Value)1U, CustomWidth = true };

Column column56 = new Column(){ Min = (UInt32Value)9U, Max = (UInt32Value)9U, Width = 1.58203125D, Style = (UInt32Value)2U, CustomWidth = true };

Column column57 = new Column(){ Min = (UInt32Value)10U, Max = (UInt32Value)10U, Width = 8.58203125D, Style = (UInt32Value)2U, CustomWidth = true };

Column column58 = new Column(){ Min = (UInt32Value)11U, Max = (UInt32Value)16384U, Width = 8.75D, Style = (UInt32Value)2U };

columns12.Append(column54);

columns12.Append(column55);

columns12.Append(column56);

columns12.Append(column57);

columns12.Append(column58);

SheetData sheetData12 = new SheetData();

Row row156 = new Row(){ RowIndex = (UInt32Value)1U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, Height = 9D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1182 = new Cell(){ CellReference = "I1", StyleIndex = (UInt32Value)2U, DataType = CellValues.SharedString };

CellValue cellValue480 = new CellValue();

cellValue480.Text = "2";

cell1182.Append(cellValue480);

row156.Append(cell1182);

Row row157 = new Row(){ RowIndex = (UInt32Value)2U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, Height = 96D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1183 = new Cell(){ CellReference = "B2", StyleIndex = (UInt32Value)52U, DataType = CellValues.String };

CellFormula cellFormula141 = new CellFormula();

cellFormula141.Text = "\"March \"&CalendarYear";

CellValue cellValue481 = new CellValue();

cellValue481.Text = "March 2019";

cell1183.Append(cellFormula141);

cell1183.Append(cellValue481);

Cell cell1184 = new Cell(){ CellReference = "C2", StyleIndex = (UInt32Value)52U };

Cell cell1185 = new Cell(){ CellReference = "D2", StyleIndex = (UInt32Value)52U };

Cell cell1186 = new Cell(){ CellReference = "E2", StyleIndex = (UInt32Value)3U };

Cell cell1187 = new Cell(){ CellReference = "F2", StyleIndex = (UInt32Value)3U };

Cell cell1188 = new Cell(){ CellReference = "G2", StyleIndex = (UInt32Value)3U };

Cell cell1189 = new Cell(){ CellReference = "H2", StyleIndex = (UInt32Value)4U };

row157.Append(cell1183);

row157.Append(cell1184);

row157.Append(cell1185);

row157.Append(cell1186);

row157.Append(cell1187);

row157.Append(cell1188);

row157.Append(cell1189);

Row row158 = new Row(){ RowIndex = (UInt32Value)3U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)13U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1190 = new Cell(){ CellReference = "A3", StyleIndex = (UInt32Value)12U };

Cell cell1191 = new Cell(){ CellReference = "B3", StyleIndex = (UInt32Value)25U, DataType = CellValues.String };

CellFormula cellFormula142 = new CellFormula();

cellFormula142.Text = "WeekStart";

CellValue cellValue482 = new CellValue();

cellValue482.Text = "Sunday";

cell1191.Append(cellFormula142);

cell1191.Append(cellValue482);

Cell cell1192 = new Cell(){ CellReference = "C3", StyleIndex = (UInt32Value)26U, DataType = CellValues.String };

CellFormula cellFormula143 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, Reference = "C3:H3", SharedIndex = (UInt32Value)0U };

cellFormula143.Text = "TEXT(C4,\"dddd\")";

CellValue cellValue483 = new CellValue();

cellValue483.Text = "Monday";

cell1192.Append(cellFormula143);

cell1192.Append(cellValue483);

Cell cell1193 = new Cell(){ CellReference = "D3", StyleIndex = (UInt32Value)26U, DataType = CellValues.String };

CellFormula cellFormula144 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, SharedIndex = (UInt32Value)0U };

cellFormula144.Text = "";

CellValue cellValue484 = new CellValue();

cellValue484.Text = "Tuesday";

cell1193.Append(cellFormula144);

cell1193.Append(cellValue484);

Cell cell1194 = new Cell(){ CellReference = "E3", StyleIndex = (UInt32Value)26U, DataType = CellValues.String };

CellFormula cellFormula145 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, SharedIndex = (UInt32Value)0U };

cellFormula145.Text = "";

CellValue cellValue485 = new CellValue();

cellValue485.Text = "Wednesday";

cell1194.Append(cellFormula145);

cell1194.Append(cellValue485);

Cell cell1195 = new Cell(){ CellReference = "F3", StyleIndex = (UInt32Value)26U, DataType = CellValues.String };

CellFormula cellFormula146 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, SharedIndex = (UInt32Value)0U };

cellFormula146.Text = "";

CellValue cellValue486 = new CellValue();

cellValue486.Text = "Thursday";

cell1195.Append(cellFormula146);

cell1195.Append(cellValue486);

Cell cell1196 = new Cell(){ CellReference = "G3", StyleIndex = (UInt32Value)26U, DataType = CellValues.String };

CellFormula cellFormula147 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, SharedIndex = (UInt32Value)0U };

cellFormula147.Text = "";

CellValue cellValue487 = new CellValue();

cellValue487.Text = "Friday";

cell1196.Append(cellFormula147);

cell1196.Append(cellValue487);

Cell cell1197 = new Cell(){ CellReference = "H3", StyleIndex = (UInt32Value)27U, DataType = CellValues.String };

CellFormula cellFormula148 = new CellFormula(){ FormulaType = CellFormulaValues.Shared, SharedIndex = (UInt32Value)0U };

cellFormula148.Text = "";

CellValue cellValue488 = new CellValue();

cellValue488.Text = "Saturday";

cell1197.Append(cellFormula148);

cell1197.Append(cellValue488);

row158.Append(cell1190);

row158.Append(cell1191);

row158.Append(cell1192);

row158.Append(cell1193);

row158.Append(cell1194);

row158.Append(cell1195);

row158.Append(cell1196);

row158.Append(cell1197);

Row row159 = new Row(){ RowIndex = (UInt32Value)4U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.35D };

Cell cell1198 = new Cell(){ CellReference = "A4", StyleIndex = (UInt32Value)5U };

Cell cell1199 = new Cell(){ CellReference = "B4", StyleIndex = (UInt32Value)28U };

CellFormula cellFormula149 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B4:H4" };

cellFormula149.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+1";

CellValue cellValue489 = new CellValue();

cellValue489.Text = "43520";

cell1199.Append(cellFormula149);

cell1199.Append(cellValue489);

Cell cell1200 = new Cell(){ CellReference = "C4", StyleIndex = (UInt32Value)28U };

CellValue cellValue490 = new CellValue();

cellValue490.Text = "43521";

cell1200.Append(cellValue490);

Cell cell1201 = new Cell(){ CellReference = "D4", StyleIndex = (UInt32Value)28U };

CellValue cellValue491 = new CellValue();

cellValue491.Text = "43522";

cell1201.Append(cellValue491);

Cell cell1202 = new Cell(){ CellReference = "E4", StyleIndex = (UInt32Value)28U };

CellValue cellValue492 = new CellValue();

cellValue492.Text = "43523";

cell1202.Append(cellValue492);

Cell cell1203 = new Cell(){ CellReference = "F4", StyleIndex = (UInt32Value)28U };

CellValue cellValue493 = new CellValue();

cellValue493.Text = "43524";

cell1203.Append(cellValue493);

Cell cell1204 = new Cell(){ CellReference = "G4", StyleIndex = (UInt32Value)28U };

CellValue cellValue494 = new CellValue();

cellValue494.Text = "43525";

cell1204.Append(cellValue494);

Cell cell1205 = new Cell(){ CellReference = "H4", StyleIndex = (UInt32Value)28U };

CellValue cellValue495 = new CellValue();

cellValue495.Text = "43526";

cell1205.Append(cellValue495);

row159.Append(cell1198);

row159.Append(cell1199);

row159.Append(cell1200);

row159.Append(cell1201);

row159.Append(cell1202);

row159.Append(cell1203);

row159.Append(cell1204);

row159.Append(cell1205);

Row row160 = new Row(){ RowIndex = (UInt32Value)5U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1206 = new Cell(){ CellReference = "A5", StyleIndex = (UInt32Value)17U };

Cell cell1207 = new Cell(){ CellReference = "B5", StyleIndex = (UInt32Value)30U };

Cell cell1208 = new Cell(){ CellReference = "C5", StyleIndex = (UInt32Value)30U };

Cell cell1209 = new Cell(){ CellReference = "D5", StyleIndex = (UInt32Value)30U };

Cell cell1210 = new Cell(){ CellReference = "E5", StyleIndex = (UInt32Value)30U };

Cell cell1211 = new Cell(){ CellReference = "F5", StyleIndex = (UInt32Value)30U };

Cell cell1212 = new Cell(){ CellReference = "G5", StyleIndex = (UInt32Value)30U };

Cell cell1213 = new Cell(){ CellReference = "H5", StyleIndex = (UInt32Value)30U };

row160.Append(cell1206);

row160.Append(cell1207);

row160.Append(cell1208);

row160.Append(cell1209);

row160.Append(cell1210);

row160.Append(cell1211);

row160.Append(cell1212);

row160.Append(cell1213);

Row row161 = new Row(){ RowIndex = (UInt32Value)6U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1214 = new Cell(){ CellReference = "A6", StyleIndex = (UInt32Value)5U };

Cell cell1215 = new Cell(){ CellReference = "B6", StyleIndex = (UInt32Value)31U };

CellFormula cellFormula150 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B6:H6" };

cellFormula150.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+8";

CellValue cellValue496 = new CellValue();

cellValue496.Text = "43527";

cell1215.Append(cellFormula150);

cell1215.Append(cellValue496);

Cell cell1216 = new Cell(){ CellReference = "C6", StyleIndex = (UInt32Value)31U };

CellValue cellValue497 = new CellValue();

cellValue497.Text = "43528";

cell1216.Append(cellValue497);

Cell cell1217 = new Cell(){ CellReference = "D6", StyleIndex = (UInt32Value)31U };

CellValue cellValue498 = new CellValue();

cellValue498.Text = "43529";

cell1217.Append(cellValue498);

Cell cell1218 = new Cell(){ CellReference = "E6", StyleIndex = (UInt32Value)31U };

CellValue cellValue499 = new CellValue();

cellValue499.Text = "43530";

cell1218.Append(cellValue499);

Cell cell1219 = new Cell(){ CellReference = "F6", StyleIndex = (UInt32Value)31U };

CellValue cellValue500 = new CellValue();

cellValue500.Text = "43531";

cell1219.Append(cellValue500);

Cell cell1220 = new Cell(){ CellReference = "G6", StyleIndex = (UInt32Value)31U };

CellValue cellValue501 = new CellValue();

cellValue501.Text = "43532";

cell1220.Append(cellValue501);

Cell cell1221 = new Cell(){ CellReference = "H6", StyleIndex = (UInt32Value)31U };

CellValue cellValue502 = new CellValue();

cellValue502.Text = "43533";

cell1221.Append(cellValue502);

row161.Append(cell1214);

row161.Append(cell1215);

row161.Append(cell1216);

row161.Append(cell1217);

row161.Append(cell1218);

row161.Append(cell1219);

row161.Append(cell1220);

row161.Append(cell1221);

Row row162 = new Row(){ RowIndex = (UInt32Value)7U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1222 = new Cell(){ CellReference = "A7", StyleIndex = (UInt32Value)17U };

Cell cell1223 = new Cell(){ CellReference = "B7", StyleIndex = (UInt32Value)29U };

Cell cell1224 = new Cell(){ CellReference = "C7", StyleIndex = (UInt32Value)29U };

Cell cell1225 = new Cell(){ CellReference = "D7", StyleIndex = (UInt32Value)29U };

Cell cell1226 = new Cell(){ CellReference = "E7", StyleIndex = (UInt32Value)29U };

Cell cell1227 = new Cell(){ CellReference = "F7", StyleIndex = (UInt32Value)29U };

Cell cell1228 = new Cell(){ CellReference = "G7", StyleIndex = (UInt32Value)29U };

Cell cell1229 = new Cell(){ CellReference = "H7", StyleIndex = (UInt32Value)29U };

row162.Append(cell1222);

row162.Append(cell1223);

row162.Append(cell1224);

row162.Append(cell1225);

row162.Append(cell1226);

row162.Append(cell1227);

row162.Append(cell1228);

row162.Append(cell1229);

Row row163 = new Row(){ RowIndex = (UInt32Value)8U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1230 = new Cell(){ CellReference = "A8", StyleIndex = (UInt32Value)5U };

Cell cell1231 = new Cell(){ CellReference = "B8", StyleIndex = (UInt32Value)32U };

CellFormula cellFormula151 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B8:H8" };

cellFormula151.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+15";

CellValue cellValue503 = new CellValue();

cellValue503.Text = "43534";

cell1231.Append(cellFormula151);

cell1231.Append(cellValue503);

Cell cell1232 = new Cell(){ CellReference = "C8", StyleIndex = (UInt32Value)32U };

CellValue cellValue504 = new CellValue();

cellValue504.Text = "43535";

cell1232.Append(cellValue504);

Cell cell1233 = new Cell(){ CellReference = "D8", StyleIndex = (UInt32Value)32U };

CellValue cellValue505 = new CellValue();

cellValue505.Text = "43536";

cell1233.Append(cellValue505);

Cell cell1234 = new Cell(){ CellReference = "E8", StyleIndex = (UInt32Value)32U };

CellValue cellValue506 = new CellValue();

cellValue506.Text = "43537";

cell1234.Append(cellValue506);

Cell cell1235 = new Cell(){ CellReference = "F8", StyleIndex = (UInt32Value)32U };

CellValue cellValue507 = new CellValue();

cellValue507.Text = "43538";

cell1235.Append(cellValue507);

Cell cell1236 = new Cell(){ CellReference = "G8", StyleIndex = (UInt32Value)32U };

CellValue cellValue508 = new CellValue();

cellValue508.Text = "43539";

cell1236.Append(cellValue508);

Cell cell1237 = new Cell(){ CellReference = "H8", StyleIndex = (UInt32Value)32U };

CellValue cellValue509 = new CellValue();

cellValue509.Text = "43540";

cell1237.Append(cellValue509);

row163.Append(cell1230);

row163.Append(cell1231);

row163.Append(cell1232);

row163.Append(cell1233);

row163.Append(cell1234);

row163.Append(cell1235);

row163.Append(cell1236);

row163.Append(cell1237);

Row row164 = new Row(){ RowIndex = (UInt32Value)9U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1238 = new Cell(){ CellReference = "A9", StyleIndex = (UInt32Value)17U };

Cell cell1239 = new Cell(){ CellReference = "B9", StyleIndex = (UInt32Value)30U };

Cell cell1240 = new Cell(){ CellReference = "C9", StyleIndex = (UInt32Value)30U };

Cell cell1241 = new Cell(){ CellReference = "D9", StyleIndex = (UInt32Value)30U };

Cell cell1242 = new Cell(){ CellReference = "E9", StyleIndex = (UInt32Value)30U };

Cell cell1243 = new Cell(){ CellReference = "F9", StyleIndex = (UInt32Value)30U };

Cell cell1244 = new Cell(){ CellReference = "G9", StyleIndex = (UInt32Value)30U };

Cell cell1245 = new Cell(){ CellReference = "H9", StyleIndex = (UInt32Value)30U };

row164.Append(cell1238);

row164.Append(cell1239);

row164.Append(cell1240);

row164.Append(cell1241);

row164.Append(cell1242);

row164.Append(cell1243);

row164.Append(cell1244);

row164.Append(cell1245);

Row row165 = new Row(){ RowIndex = (UInt32Value)10U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1246 = new Cell(){ CellReference = "A10", StyleIndex = (UInt32Value)5U };

Cell cell1247 = new Cell(){ CellReference = "B10", StyleIndex = (UInt32Value)31U };

CellFormula cellFormula152 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B10:H10" };

cellFormula152.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+22";

CellValue cellValue510 = new CellValue();

cellValue510.Text = "43541";

cell1247.Append(cellFormula152);

cell1247.Append(cellValue510);

Cell cell1248 = new Cell(){ CellReference = "C10", StyleIndex = (UInt32Value)31U };

CellValue cellValue511 = new CellValue();

cellValue511.Text = "43542";

cell1248.Append(cellValue511);

Cell cell1249 = new Cell(){ CellReference = "D10", StyleIndex = (UInt32Value)31U };

CellValue cellValue512 = new CellValue();

cellValue512.Text = "43543";

cell1249.Append(cellValue512);

Cell cell1250 = new Cell(){ CellReference = "E10", StyleIndex = (UInt32Value)31U };

CellValue cellValue513 = new CellValue();

cellValue513.Text = "43544";

cell1250.Append(cellValue513);

Cell cell1251 = new Cell(){ CellReference = "F10", StyleIndex = (UInt32Value)31U };

CellValue cellValue514 = new CellValue();

cellValue514.Text = "43545";

cell1251.Append(cellValue514);

Cell cell1252 = new Cell(){ CellReference = "G10", StyleIndex = (UInt32Value)31U };

CellValue cellValue515 = new CellValue();

cellValue515.Text = "43546";

cell1252.Append(cellValue515);

Cell cell1253 = new Cell(){ CellReference = "H10", StyleIndex = (UInt32Value)31U };

CellValue cellValue516 = new CellValue();

cellValue516.Text = "43547";

cell1253.Append(cellValue516);

row165.Append(cell1246);

row165.Append(cell1247);

row165.Append(cell1248);

row165.Append(cell1249);

row165.Append(cell1250);

row165.Append(cell1251);

row165.Append(cell1252);

row165.Append(cell1253);

Row row166 = new Row(){ RowIndex = (UInt32Value)11U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1254 = new Cell(){ CellReference = "A11", StyleIndex = (UInt32Value)17U };

Cell cell1255 = new Cell(){ CellReference = "B11", StyleIndex = (UInt32Value)29U };

Cell cell1256 = new Cell(){ CellReference = "C11", StyleIndex = (UInt32Value)29U };

Cell cell1257 = new Cell(){ CellReference = "D11", StyleIndex = (UInt32Value)29U };

Cell cell1258 = new Cell(){ CellReference = "E11", StyleIndex = (UInt32Value)29U };

Cell cell1259 = new Cell(){ CellReference = "F11", StyleIndex = (UInt32Value)29U };

Cell cell1260 = new Cell(){ CellReference = "G11", StyleIndex = (UInt32Value)29U };

Cell cell1261 = new Cell(){ CellReference = "H11", StyleIndex = (UInt32Value)29U };

row166.Append(cell1254);

row166.Append(cell1255);

row166.Append(cell1256);

row166.Append(cell1257);

row166.Append(cell1258);

row166.Append(cell1259);

row166.Append(cell1260);

row166.Append(cell1261);

Row row167 = new Row(){ RowIndex = (UInt32Value)12U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1262 = new Cell(){ CellReference = "A12", StyleIndex = (UInt32Value)5U };

Cell cell1263 = new Cell(){ CellReference = "B12", StyleIndex = (UInt32Value)32U };

CellFormula cellFormula153 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B12:H12" };

cellFormula153.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+29";

CellValue cellValue517 = new CellValue();

cellValue517.Text = "43548";

cell1263.Append(cellFormula153);

cell1263.Append(cellValue517);

Cell cell1264 = new Cell(){ CellReference = "C12", StyleIndex = (UInt32Value)32U };

CellValue cellValue518 = new CellValue();

cellValue518.Text = "43549";

cell1264.Append(cellValue518);

Cell cell1265 = new Cell(){ CellReference = "D12", StyleIndex = (UInt32Value)32U };

CellValue cellValue519 = new CellValue();

cellValue519.Text = "43550";

cell1265.Append(cellValue519);

Cell cell1266 = new Cell(){ CellReference = "E12", StyleIndex = (UInt32Value)32U };

CellValue cellValue520 = new CellValue();

cellValue520.Text = "43551";

cell1266.Append(cellValue520);

Cell cell1267 = new Cell(){ CellReference = "F12", StyleIndex = (UInt32Value)32U };

CellValue cellValue521 = new CellValue();

cellValue521.Text = "43552";

cell1267.Append(cellValue521);

Cell cell1268 = new Cell(){ CellReference = "G12", StyleIndex = (UInt32Value)32U };

CellValue cellValue522 = new CellValue();

cellValue522.Text = "43553";

cell1268.Append(cellValue522);

Cell cell1269 = new Cell(){ CellReference = "H12", StyleIndex = (UInt32Value)32U };

CellValue cellValue523 = new CellValue();

cellValue523.Text = "43554";

cell1269.Append(cellValue523);

row167.Append(cell1262);

row167.Append(cell1263);

row167.Append(cell1264);

row167.Append(cell1265);

row167.Append(cell1266);

row167.Append(cell1267);

row167.Append(cell1268);

row167.Append(cell1269);

Row row168 = new Row(){ RowIndex = (UInt32Value)13U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1270 = new Cell(){ CellReference = "A13", StyleIndex = (UInt32Value)17U };

Cell cell1271 = new Cell(){ CellReference = "B13", StyleIndex = (UInt32Value)30U };

Cell cell1272 = new Cell(){ CellReference = "C13", StyleIndex = (UInt32Value)30U };

Cell cell1273 = new Cell(){ CellReference = "D13", StyleIndex = (UInt32Value)30U };

Cell cell1274 = new Cell(){ CellReference = "E13", StyleIndex = (UInt32Value)30U };

Cell cell1275 = new Cell(){ CellReference = "F13", StyleIndex = (UInt32Value)30U };

Cell cell1276 = new Cell(){ CellReference = "G13", StyleIndex = (UInt32Value)30U };

Cell cell1277 = new Cell(){ CellReference = "H13", StyleIndex = (UInt32Value)30U };

row168.Append(cell1270);

row168.Append(cell1271);

row168.Append(cell1272);

row168.Append(cell1273);

row168.Append(cell1274);

row168.Append(cell1275);

row168.Append(cell1276);

row168.Append(cell1277);

Row row169 = new Row(){ RowIndex = (UInt32Value)14U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)6U, CustomFormat = true, Height = 24D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1278 = new Cell(){ CellReference = "A14", StyleIndex = (UInt32Value)5U };

Cell cell1279 = new Cell(){ CellReference = "B14", StyleIndex = (UInt32Value)31U };

CellFormula cellFormula154 = new CellFormula(){ FormulaType = CellFormulaValues.Array, Reference = "B14:C14" };

cellFormula154.Text = "DaysAndWeeks+DATE(CalendarYear,3,1)-WEEKDAY(DATE(CalendarYear,3,1),(WeekStart=\"Monday\")+1)+36";

CellValue cellValue524 = new CellValue();

cellValue524.Text = "43555";

cell1279.Append(cellFormula154);

cell1279.Append(cellValue524);

Cell cell1280 = new Cell(){ CellReference = "C14", StyleIndex = (UInt32Value)31U };

CellValue cellValue525 = new CellValue();

cellValue525.Text = "43556";

cell1280.Append(cellValue525);

Cell cell1281 = new Cell(){ CellReference = "D14", StyleIndex = (UInt32Value)53U, DataType = CellValues.SharedString };

CellValue cellValue526 = new CellValue();

cellValue526.Text = "1";

cell1281.Append(cellValue526);

Cell cell1282 = new Cell(){ CellReference = "E14", StyleIndex = (UInt32Value)53U };

Cell cell1283 = new Cell(){ CellReference = "F14", StyleIndex = (UInt32Value)53U };

Cell cell1284 = new Cell(){ CellReference = "G14", StyleIndex = (UInt32Value)53U };

Cell cell1285 = new Cell(){ CellReference = "H14", StyleIndex = (UInt32Value)54U };

row169.Append(cell1278);

row169.Append(cell1279);

row169.Append(cell1280);

row169.Append(cell1281);

row169.Append(cell1282);

row169.Append(cell1283);

row169.Append(cell1284);

row169.Append(cell1285);

Row row170 = new Row(){ RowIndex = (UInt32Value)15U, Spans = new ListValue<StringValue>() { InnerText = "1:9" }, StyleIndex = (UInt32Value)18U, CustomFormat = true, Height = 56.15D, CustomHeight = true, DyDescent = 0.25D };

Cell cell1286 = new Cell(){ CellReference = "A15", StyleIndex = (UInt32Value)17U };

Cell cell1287 = new Cell(){ CellReference = "B15", StyleIndex = (UInt32Value)29U };

Cell cell1288 = new Cell(){ CellReference = "C15", StyleIndex = (UInt32Value)29U };

Cell cell1289 = new Cell(){ CellReference = "D15", StyleIndex = (UInt32Value)55U };

Cell cell1290 = new Cell(){ CellReference = "E15", StyleIndex = (UInt32Value)55U };

Cell cell1291 = new Cell(){ CellReference = "F15", StyleIndex = (UInt32Value)55U };

Cell cell1292 = new Cell(){ CellReference = "G15", StyleIndex = (UInt32Value)55U };

Cell cell1293 = new Cell(){ CellReference = "H15", StyleIndex = (UInt32Value)56U };

row170.Append(cell1286);

row170.Append(cell1287);

row170.Append(cell1288);

row170.Append(cell1289);

row170.Append(cell1290);

row170.Append(cell1291);

row170.Append(cell1292);

row170.Append(cell1293);

sheetData12.Append(row156);

sheetData12.Append(row157);

sheetData12.Append(row158);

sheetData12.Append(row159);

sheetData12.Append(row160);

sheetData12.Append(row161);

sheetData12.Append(row162);

sheetData12.Append(row163);

sheetData12.Append(row164);

sheetData12.Append(row165);

sheetData12.Append(row166);

sheetData12.Append(row167);

sheetData12.Append(row168);

sheetData12.Append(row169);

sheetData12.Append(row170);

MergeCells mergeCells12 = new MergeCells(){ Count = (UInt32Value)3U };

MergeCell mergeCell36 = new MergeCell(){ Reference = "B2:D2" };

MergeCell mergeCell37 = new MergeCell(){ Reference = "D14:H14" };

MergeCell mergeCell38 = new MergeCell(){ Reference = "D15:H15" };

mergeCells12.Append(mergeCell36);

mergeCells12.Append(mergeCell37);

mergeCells12.Append(mergeCell38);

ConditionalFormatting conditionalFormatting21 = new ConditionalFormatting(){ SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B12:H12 B14:C14" } };

ConditionalFormattingRule conditionalFormattingRule21 = new ConditionalFormattingRule(){ Type = ConditionalFormatValues.Expression, FormatId = (UInt32Value)19U, Priority = 2 };

Formula formula21 = new Formula();

formula21.Text = "AND(DAY(B12)>=1,DAY(B12)<=15)";

conditionalFormattingRule21.Append(formula21);

conditionalFormatting21.Append(conditionalFormattingRule21);

ConditionalFormatting conditionalFormatting22 = new ConditionalFormatting(){ SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B4:G4" } };

ConditionalFormattingRule conditionalFormattingRule22 = new ConditionalFormattingRule(){ Type = ConditionalFormatValues.Expression, FormatId = (UInt32Value)18U, Priority = 1 };

Formula formula22 = new Formula();

formula22.Text = "DAY(B4)>8";

conditionalFormattingRule22.Append(formula22);

conditionalFormatting22.Append(conditionalFormattingRule22);

DataValidations dataValidations11 = new DataValidations(){ Count = (UInt32Value)8U };

DataValidation dataValidation86 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "March month calendar", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A1" } };

dataValidation86.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000000000000}"));

DataValidation dataValidation87 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "The year in this cell is automatically updated based on year entered in January worksheet. Calendar below has dates for previous and next month with lighter font shade", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B2:D2" } };

dataValidation87.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000001000000}"));

DataValidation dataValidation88 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "Automatically determined weekday", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "C3:H3" } };

dataValidation88.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000002000000}"));

DataValidation dataValidation89 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "This row & rows 6, 8, 10, 12 & 14 contain calendar days of the week. If this cell doesn't contain the number 1, then it is a day from the previous month. Enter notes in cell D15.", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B4" } };

dataValidation89.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000003000000}"));

DataValidation dataValidation90 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "This row & rows 7, 9, 11, 13, & 15 are cells for entering daily notes related to the calendar day in the cell above.", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B5" } };

dataValidation90.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000004000000}"));

DataValidation dataValidation91 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, Prompt = "Enter monthly Notes in this cell", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "D15:H15" } };

dataValidation91.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000005000000}"));

DataValidation dataValidation92 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, Prompt = "Enter monthly Notes in cell below", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "D14:H14" } };

dataValidation92.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000006000000}"));

DataValidation dataValidation93 = new DataValidation(){ AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, Prompt = "This row contains weekday names for this calendar. This cell contains the starting day of the week. To change week start day, select a new weekday in January worksheet cell L5.", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "B3" } };

dataValidation93.SetAttribute(new OpenXmlAttribute("xr", "uid", "http://schemas.microsoft.com/office/spreadsheetml/2014/revision", "{00000000-0002-0000-0200-000007000000}"));

dataValidations11.Append(dataValidation86);

dataValidations11.Append(dataValidation87);

dataValidations11.Append(dataValidation88);

dataValidations11.Append(dataValidation89);

dataValidations11.Append(dataValidation90);

dataValidations11.Append(dataValidation91);

dataValidations11.Append(dataValidation92);

dataValidations11.Append(dataValidation93);

PrintOptions printOptions11 = new PrintOptions(){ HorizontalCentered = true };

PageMargins pageMargins12 = new PageMargins(){ Left = 0.25D, Right = 0.25D, Top = 0.5D, Bottom = 0.5D, Header = 0.3D, Footer = 0.3D };

PageSetup pageSetup11 = new PageSetup(){ Orientation = OrientationValues.Landscape, Id = "rId1" };

HeaderFooter headerFooter11 = new HeaderFooter(){ DifferentFirst = true };

Drawing drawing11 = new Drawing(){ Id = "rId2" };

worksheet12.Append(sheetProperties11);

worksheet12.Append(sheetDimension12);

worksheet12.Append(sheetViews12);

worksheet12.Append(sheetFormatProperties12);

worksheet12.Append(columns12);

worksheet12.Append(sheetData12);

worksheet12.Append(mergeCells12);

worksheet12.Append(conditionalFormatting21);

worksheet12.Append(conditionalFormatting22);

worksheet12.Append(dataValidations11);

worksheet12.Append(printOptions11);

worksheet12.Append(pageMargins12);

worksheet12.Append(pageSetup11);

worksheet12.Append(headerFooter11);

worksheet12.Append(drawing11);

worksheetPart12.Worksheet = worksheet12;

}

相关推荐
向宇it44 分钟前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例
开发语言·游戏·unity·c#·游戏引擎
九鼎科技-Leo1 小时前
什么是 WPF 中的依赖属性?有什么作用?
windows·c#·.net·wpf
朝九晚五ฺ2 小时前
【Linux探索学习】第十四弹——进程优先级:深入理解操作系统中的进程优先级
linux·运维·学习
Heaphaestus,RC2 小时前
【Unity3D】获取 GameObject 的完整层级结构
unity·c#
baivfhpwxf20232 小时前
C# 5000 转16进制 字节(激光器串口通讯生成指定格式命令)
开发语言·c#
直裾3 小时前
Scala全文单词统计
开发语言·c#·scala
猫爪笔记3 小时前
前端:HTML (学习笔记)【1】
前端·笔记·学习·html
开心点幸运点4 小时前
Excel——宏教程(1)
excel
小白不太白9504 小时前
设计模式之 外观模式
microsoft·设计模式·外观模式
pq113_64 小时前
ftdi_sio应用学习笔记 3 - GPIO
笔记·学习·ftdi_sio