Skip to content

Commit b16f0be

Browse files
committed
开源 DocumentFormat.OpenXml.Flatten 库
1 parent 6dd135c commit b16f0be

252 files changed

Lines changed: 48699 additions & 16 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
<Description>A dotnet tool to assist in editing Office document files</Description>
1212

1313
<RepositoryType>git</RepositoryType>
14-
<Copyright>Copyright © 2020 dotnet campus, All Rights Reserved.</Copyright>
14+
<Copyright>Copyright © 2020-2021 dotnet campus, All Rights Reserved.</Copyright>
1515
</PropertyGroup>
1616
</Project>

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ OfficeDocumentZipper
3636
|--|--|
3737
|dotnetCampus.OpenXMLUnitConverter|[![](https://img.shields.io/nuget/v/dotnetCampus.OpenXMLUnitConverter.svg)](https://www.nuget.org/packages/dotnetCampus.OpenXMLUnitConverter)|
3838
|dotnetCampus.OpenXMLUnitConverter.Source|[![](https://img.shields.io/nuget/v/dotnetCampus.OpenXMLUnitConverter.Source.svg)](https://www.nuget.org/packages/dotnetCampus.OpenXMLUnitConverter.Source)|
39-
39+
|dotnetCampus.DocumentFormat.OpenXml.Flatten|[![](https://img.shields.io/nuget/v/dotnetCampus.DocumentFormat.OpenXml.Flatten.svg)](https://www.nuget.org/packages/dotnetCampus.DocumentFormat.OpenXml.Flatten)|
40+
|dotnetCampus.DocumentFormat.OpenXml.Flatten.Source|[![](https://img.shields.io/nuget/v/dotnetCampus.DocumentFormat.OpenXml.Flatten.Source.svg)](https://www.nuget.org/packages/dotnetCampus.DocumentFormat.OpenXml.Flatten.Source)|
4041

4142
## dotnetCampus.OpenXMLUnitConverter
4243

@@ -47,13 +48,13 @@ Defining units for OpenXml properties and the unit conversion function.
4748
DLL Pakcage:
4849

4950
```xml
50-
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter" Version="1.8.0" />
51+
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter" Version="1.9.0" />
5152
```
5253

5354
[SouceYard](https://github.com/dotnet-campus/SourceYard) Package:
5455

5556
```xml
56-
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter.Source" Version="1.8.0">
57+
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter.Source" Version="1.9.0">
5758
<PrivateAssets>all</PrivateAssets>
5859
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
5960
</PackageReference>
@@ -72,6 +73,30 @@ void Foo(DocumentFormat.OpenXml.Drawing.Point2DType point)
7273
}
7374
```
7475

76+
## DocumentFormat.OpenXml.Flatten
77+
78+
### Install
79+
80+
DLL Pakcage:
81+
82+
```xml
83+
<PackageReference Include="dotnetCampus.DocumentFormat.OpenXml.Flatten" Version="2.0.0" />
84+
```
85+
86+
[SouceYard](https://github.com/dotnet-campus/SourceYard) Package:
87+
88+
```xml
89+
<PackageReference Include="dotnetCampus.DocumentFormat.OpenXml.Flatten.Source" Version="2.0.0">
90+
<PrivateAssets>all</PrivateAssets>
91+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
92+
</PackageReference>
93+
```
94+
95+
### Usage
96+
97+
See [DocumentFormat.OpenXml.Flatten README.md](src/DocumentFormat.OpenXml.Flatten/README.md)
98+
99+
75100
# Thanks
76101

77102
- [OfficeDev/Open-XML-SDK: Open XML SDK by Microsoft](https://github.com/OfficeDev/Open-XML-SDK/ )

README.zh-cn.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ OfficeDocumentZipper
5353
DLL 包:
5454

5555
```xml
56-
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter" Version="1.8.0" />
56+
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter" Version="1.9.0" />
5757
```
5858

5959
[SouceYard](https://github.com/dotnet-campus/SourceYard) 源代码包:
6060

6161
```xml
62-
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter.Source" Version="1.8.0">
62+
<PackageReference Include="dotnetCampus.OpenXmlUnitConverter.Source" Version="1.9.0">
6363
<PrivateAssets>all</PrivateAssets>
6464
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
6565
</PackageReference>
@@ -80,6 +80,31 @@ void Foo(DocumentFormat.OpenXml.Drawing.Point2DType point)
8080

8181
详细请看 [Office Open XML 的测量单位](https://blog.lindexi.com/post/Office-Open-XML-%E7%9A%84%E6%B5%8B%E9%87%8F%E5%8D%95%E4%BD%8D.html )
8282

83+
## DocumentFormat.OpenXml.Flatten
84+
85+
提供继承的属性拍平的功能的库,包含常用处理逻辑和计算逻辑
86+
87+
### 安装方法
88+
89+
DLL 包:
90+
91+
```xml
92+
<PackageReference Include="dotnetCampus.DocumentFormat.OpenXml.Flatten" Version="2.0.0" />
93+
```
94+
95+
[SouceYard](https://github.com/dotnet-campus/SourceYard) 源代码包:
96+
97+
```xml
98+
<PackageReference Include="dotnetCampus.DocumentFormat.OpenXml.Flatten.Source" Version="2.0.0">
99+
<PrivateAssets>all</PrivateAssets>
100+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
101+
</PackageReference>
102+
```
103+
104+
### 使用方法
105+
106+
具体使用方法请参阅 [DocumentFormat.OpenXml.Flatten 使用文档](src/DocumentFormat.OpenXml.Flatten/README.md)
107+
83108
# 感谢
84109

85110
- [OfficeDev/Open-XML-SDK: Open XML SDK by Microsoft](https://github.com/OfficeDev/Open-XML-SDK/ )

dotnetCampus.OfficeDocumentZipper.sln

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.30204.135
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5D196596-756D-45C2-8A05-C8E4AB8A36E6}"
7-
EndProject
86
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.OfficeDocumentZipper", "src\dotnetCampus.OfficeDocumentZipper\dotnetCampus.OfficeDocumentZipper.csproj", "{EF60ACE4-91B3-4731-8530-F3CD922E922D}"
97
EndProject
108
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A80DBE61-A86F-4F1E-B638-999F15ED9EE3}"
@@ -14,15 +12,25 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1412
CHANGELOG.md = CHANGELOG.md
1513
Directory.Build.props = Directory.Build.props
1614
README.md = README.md
15+
README.zh-cn.md = README.zh-cn.md
1716
build\Version.props = build\Version.props
1817
EndProjectSection
1918
EndProject
2019
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.OpenXmlUnitConverter", "src\dotnetCampus.OpenXmlUnitConverter\dotnetCampus.OpenXmlUnitConverter.csproj", "{DFF5A479-FCEE-431D-85C6-8E0D03E64F46}"
2120
EndProject
22-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{66E18386-803A-464D-9006-2EFD364FE97C}"
23-
EndProject
2421
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.OpenXMLUnitConverter.Tests", "tests\dotnetCampus.OpenXMLUnitConverter.Tests\dotnetCampus.OpenXMLUnitConverter.Tests.csproj", "{86010F5E-F7FD-40C9-96D7-491356A90139}"
2522
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DocumentFormat.OpenXml.Flatten", "DocumentFormat.OpenXml.Flatten", "{1DCDA9B1-ED7A-4825-BBA3-E3561006E4AF}"
24+
ProjectSection(SolutionItems) = preProject
25+
src\DocumentFormat.OpenXml.Flatten\README.md = src\DocumentFormat.OpenXml.Flatten\README.md
26+
EndProjectSection
27+
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnetCampus.DocumentFormat.OpenXml.Flatten", "src\DocumentFormat.OpenXml.Flatten\DocumentFormat.OpenXml.Flatten\dotnetCampus.DocumentFormat.OpenXml.Flatten.csproj", "{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6}"
29+
EndProject
30+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tool", "Tool", "{8A1ED232-9A93-4D88-AC6D-3E3D4EA98FAD}"
31+
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "OpenXmlUnitConverter", "OpenXmlUnitConverter", "{D0552FF1-B2AE-4878-B6B7-F792C326371C}"
33+
EndProject
2634
Global
2735
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2836
Debug|Any CPU = Debug|Any CPU
@@ -41,14 +49,19 @@ Global
4149
{86010F5E-F7FD-40C9-96D7-491356A90139}.Debug|Any CPU.Build.0 = Debug|Any CPU
4250
{86010F5E-F7FD-40C9-96D7-491356A90139}.Release|Any CPU.ActiveCfg = Release|Any CPU
4351
{86010F5E-F7FD-40C9-96D7-491356A90139}.Release|Any CPU.Build.0 = Release|Any CPU
52+
{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53+
{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
54+
{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
55+
{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6}.Release|Any CPU.Build.0 = Release|Any CPU
4456
EndGlobalSection
4557
GlobalSection(SolutionProperties) = preSolution
4658
HideSolutionNode = FALSE
4759
EndGlobalSection
4860
GlobalSection(NestedProjects) = preSolution
49-
{EF60ACE4-91B3-4731-8530-F3CD922E922D} = {5D196596-756D-45C2-8A05-C8E4AB8A36E6}
50-
{DFF5A479-FCEE-431D-85C6-8E0D03E64F46} = {5D196596-756D-45C2-8A05-C8E4AB8A36E6}
51-
{86010F5E-F7FD-40C9-96D7-491356A90139} = {66E18386-803A-464D-9006-2EFD364FE97C}
61+
{EF60ACE4-91B3-4731-8530-F3CD922E922D} = {8A1ED232-9A93-4D88-AC6D-3E3D4EA98FAD}
62+
{DFF5A479-FCEE-431D-85C6-8E0D03E64F46} = {D0552FF1-B2AE-4878-B6B7-F792C326371C}
63+
{86010F5E-F7FD-40C9-96D7-491356A90139} = {D0552FF1-B2AE-4878-B6B7-F792C326371C}
64+
{6003FD01-7DC7-4F99-8878-7AE3ABF40BE6} = {1DCDA9B1-ED7A-4825-BBA3-E3561006E4AF}
5265
EndGlobalSection
5366
GlobalSection(ExtensibilityGlobals) = postSolution
5467
SolutionGuid = {90F871FB-EAC2-449B-8601-3562C03CC566}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using DocumentFormat.OpenXml.Flatten.ElementConverters.CommonElement;
2+
3+
using dotnetCampus.OpenXmlUnitConverter;
4+
5+
namespace DocumentFormat.OpenXml.Flatten.Contexts
6+
{
7+
/// <summary>
8+
/// 使用 Emu 单位的形状里的文本范围,对应 OpenXml Shape 的 a:rect 标签
9+
/// </summary>
10+
public readonly struct EmuShapeTextRectangle
11+
{
12+
/// <summary>
13+
/// 创建形状里的文本范围
14+
/// </summary>
15+
public EmuShapeTextRectangle(Emu left, Emu top, Emu right, Emu bottom)
16+
{
17+
var emuWidth = new Emu(right.Value - left.Value);
18+
var emuHeight = new Emu(bottom.Value - top.Value);
19+
20+
OriginPoint = new EmuPoint(left, top);
21+
Size = new EmuSize(emuWidth, emuHeight);
22+
}
23+
24+
/// <summary>
25+
/// 创建形状里的文本范围
26+
/// </summary>
27+
/// <param name="size">形状文本框的大小</param>
28+
/// <param name="originPoint">形状文本框的原点坐标</param>
29+
public EmuShapeTextRectangle(EmuSize size, EmuPoint originPoint)
30+
{
31+
Size = size;
32+
OriginPoint = originPoint;
33+
}
34+
35+
/// <summary>
36+
/// 形状文本框的坐标原点
37+
/// </summary>
38+
public EmuPoint OriginPoint { get; }
39+
40+
/// <summary>
41+
/// Rectangle的大小
42+
/// </summary>
43+
public EmuSize Size { get; }
44+
}
45+
46+
/// <summary>
47+
/// Emu单位的形状文本框的Margin
48+
/// </summary>
49+
public readonly struct EmuTextMargin
50+
{
51+
/// <summary>
52+
/// 创建EmuTextMargin
53+
/// </summary>
54+
/// <param name="emuLeftInset">emu单位的LeftInset</param>
55+
/// <param name="emuTopInset">emu单位的TopInset</param>
56+
/// <param name="emuRightInset">emu单位的RightInset</param>
57+
/// <param name="emuBottomInset">emu单位的BottomInset</param>
58+
public EmuTextMargin(double emuLeftInset, double emuTopInset, double emuRightInset, double emuBottomInset)
59+
{
60+
LeftInset = new Emu(emuLeftInset);
61+
TopInset = new Emu(emuTopInset);
62+
RightInset = new Emu(emuRightInset);
63+
BottomInset = new Emu(emuBottomInset);
64+
}
65+
66+
/// <summary>
67+
/// 对应 a:bodyPr lIns
68+
/// </summary>
69+
public Emu LeftInset { get; }
70+
71+
/// <summary>
72+
/// 对应 a:bodyPr rIns
73+
/// </summary>
74+
public Emu RightInset { get; }
75+
76+
/// <summary>
77+
/// 对应 a:bodyPr bIns
78+
/// </summary>
79+
public Emu BottomInset { get; }
80+
81+
/// <summary>
82+
/// 对应 a:bodyPr tIns
83+
/// </summary>
84+
public Emu TopInset { get; }
85+
}
86+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using DocumentFormat.OpenXml.Drawing;
2+
3+
using dotnetCampus.OpenXmlUnitConverter;
4+
5+
namespace DocumentFormat.OpenXml.Flatten.Contexts
6+
{
7+
/// <summary>
8+
/// 对应PPT的Shape Path
9+
/// </summary>
10+
public readonly struct ShapePath
11+
{
12+
/// <summary>
13+
/// 创建PPT的Geometry Path
14+
/// </summary>
15+
/// <param name="path">OpenXml Path字符串</param>
16+
/// <param name="fillMode">OpenXml的Path Fill Mode </param>
17+
/// <param name="isStroke">是否有轮廓</param>
18+
/// <param name="isExtrusionOk">指定使用 3D 拉伸可能在此路径</param>
19+
/// <param name="emuWidth">指定的宽度或在路径坐标系统中应在使用的最大的 x 坐标</param>
20+
/// <param name="emuHeight">指定框架的高度或在路径坐标系统中应在使用的最大的 y 坐标</param>
21+
public ShapePath(string path, PathFillModeValues fillMode = PathFillModeValues.Norm, bool isStroke = true, bool isExtrusionOk = false, double emuWidth = 0, double emuHeight = 0)
22+
{
23+
Path = path;
24+
IsStroke = isStroke;
25+
FillMode = fillMode;
26+
IsFilled = fillMode is not PathFillModeValues.None;
27+
IsExtrusionOk = isExtrusionOk;
28+
Width = new Emu(emuWidth);
29+
Height = new Emu(emuHeight);
30+
}
31+
32+
/// <summary>
33+
/// 创建PPT的Geometry Path
34+
/// </summary>
35+
/// <param name="path">OpenXml Path字符串</param>
36+
/// <param name="eumWidth">指定的宽度或在路径坐标系统中应在使用的最大的 x 坐标</param>
37+
/// <param name="eumHeight">指定框架的高度或在路径坐标系统中应在使用的最大的 y 坐标</param>
38+
public ShapePath(string path, double eumWidth, double eumHeight) : this(path, PathFillModeValues.Norm, emuWidth: eumWidth, emuHeight: eumHeight)
39+
{
40+
41+
}
42+
43+
/// <summary>
44+
/// 是否填充
45+
/// </summary>
46+
public bool IsFilled { get; }
47+
48+
/// <summary>
49+
/// OpenXml 的 Path Stroke, 默认true
50+
/// </summary>
51+
public bool IsStroke { get; }
52+
53+
/// <summary>
54+
/// OpenXml的Path Fill Mode
55+
/// </summary>
56+
public PathFillModeValues FillMode { get; }
57+
58+
/// <summary>
59+
///OpenXml Path字符串
60+
/// </summary>
61+
public string Path { get; }
62+
63+
/// <summary>
64+
/// 指定使用 3D 拉伸可能在此路径,默认false或0
65+
/// </summary>
66+
public bool IsExtrusionOk { get; }
67+
68+
/// <summary>
69+
/// 指定的宽度或在路径坐标系统中应在使用的最大的 x 坐标。默认是 0 的值
70+
/// </summary>
71+
public Emu Width { get; }
72+
73+
/// <summary>
74+
/// 指定框架的高度或在路径坐标系统中应在使用的最大的 y 坐标。默认是 0 的值
75+
/// </summary>
76+
public Emu Height { get; }
77+
}
78+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using dotnetCampus.OpenXmlUnitConverter;
2+
3+
namespace DocumentFormat.OpenXml.Flatten.Contexts
4+
{
5+
/// <summary>
6+
/// 页面的使用 EMU 单位表示的 Size 尺寸
7+
/// </summary>
8+
public readonly struct SlideEmuSize
9+
{
10+
/// <summary>
11+
/// 创建使用 EMU 单位表示的 Size 尺寸
12+
/// </summary>
13+
/// <param name="width"></param>
14+
/// <param name="height"></param>
15+
public SlideEmuSize(Emu width, Emu height)
16+
{
17+
Width = width;
18+
Height = height;
19+
}
20+
21+
/// <summary>
22+
/// 宽度
23+
/// </summary>
24+
public Emu Width { get; }
25+
/// <summary>
26+
/// 高度
27+
/// </summary>
28+
public Emu Height { get; }
29+
}
30+
}

0 commit comments

Comments
 (0)