Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
Kivii.Client.OfficeSample
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
示例代码
Kivii.Client.OfficeSample
Commits
02f8cb74
Commit
02f8cb74
authored
Sep 18, 2019
by
施晓雨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
c45803e7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
245 additions
and
72 deletions
+245
-72
Contract.cs
Kivii.Client.OfficeSample/Entitis/Contract.cs
+0
-0
Form1.Designer.cs
Kivii.Client.OfficeSample/Form1.Designer.cs
+0
-47
Form1.cs
Kivii.Client.OfficeSample/Form1.cs
+0
-19
FrmMain.Designer.cs
Kivii.Client.OfficeSample/FrmMain.Designer.cs
+166
-0
FrmMain.cs
Kivii.Client.OfficeSample/FrmMain.cs
+66
-0
FrmMain.resx
Kivii.Client.OfficeSample/FrmMain.resx
+0
-0
Kivii.Client.OfficeSample.csproj
Kivii.Client.OfficeSample/Kivii.Client.OfficeSample.csproj
+10
-5
Program.cs
Kivii.Client.OfficeSample/Program.cs
+1
-1
packages.config
Kivii.Client.OfficeSample/packages.config
+2
-0
No files found.
Kivii.Client.OfficeSample/Entitis/Contract.cs
0 → 100644
View file @
02f8cb74
This diff is collapsed.
Click to expand it.
Kivii.Client.OfficeSample/Form1.Designer.cs
deleted
100644 → 0
View file @
c45803e7
namespace
Kivii.Client.OfficeSample
{
partial
class
Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private
System
.
ComponentModel
.
IContainer
components
=
null
;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected
override
void
Dispose
(
bool
disposing
)
{
if
(
disposing
&&
(
components
!=
null
))
{
components
.
Dispose
();
}
base
.
Dispose
(
disposing
);
}
#
region
Windows
窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private
void
InitializeComponent
()
{
this
.
SuspendLayout
();
//
// Form1
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
791
,
468
);
this
.
Name
=
"Form1"
;
this
.
Text
=
"Form1"
;
this
.
ResumeLayout
(
false
);
}
#
endregion
}
}
Kivii.Client.OfficeSample/Form1.cs
deleted
100644 → 0
View file @
c45803e7
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
using
System.Windows.Forms
;
namespace
Kivii.Client.OfficeSample
{
public
partial
class
Form1
:
Form
{
public
Form1
()
{
InitializeComponent
();
}
}
}
Kivii.Client.OfficeSample/FrmMain.Designer.cs
0 → 100644
View file @
02f8cb74
namespace
Kivii.Client.OfficeSample
{
partial
class
FrmMain
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private
System
.
ComponentModel
.
IContainer
components
=
null
;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected
override
void
Dispose
(
bool
disposing
)
{
if
(
disposing
&&
(
components
!=
null
))
{
components
.
Dispose
();
}
base
.
Dispose
(
disposing
);
}
#
region
Windows
窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private
void
InitializeComponent
()
{
this
.
btnGetReport
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
label1
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
tbxReportId
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
label2
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
tbxServiceUrl
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
pgResult
=
new
System
.
Windows
.
Forms
.
PropertyGrid
();
this
.
btnGenerateXlsx
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
label3
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
tbxTemplateFileName
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
btnSelectTemplateFile
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
SuspendLayout
();
//
// btnGetReport
//
this
.
btnGetReport
.
Location
=
new
System
.
Drawing
.
Point
(
256
,
72
);
this
.
btnGetReport
.
Name
=
"btnGetReport"
;
this
.
btnGetReport
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
23
);
this
.
btnGetReport
.
TabIndex
=
0
;
this
.
btnGetReport
.
Text
=
"获取"
;
this
.
btnGetReport
.
UseVisualStyleBackColor
=
true
;
this
.
btnGetReport
.
Click
+=
new
System
.
EventHandler
(
this
.
btnGetReport_Click
);
//
// label1
//
this
.
label1
.
AutoSize
=
true
;
this
.
label1
.
Location
=
new
System
.
Drawing
.
Point
(
41
,
77
);
this
.
label1
.
Name
=
"label1"
;
this
.
label1
.
Size
=
new
System
.
Drawing
.
Size
(
41
,
12
);
this
.
label1
.
TabIndex
=
1
;
this
.
label1
.
Text
=
"报告号"
;
//
// tbxReportId
//
this
.
tbxReportId
.
Location
=
new
System
.
Drawing
.
Point
(
88
,
74
);
this
.
tbxReportId
.
Name
=
"tbxReportId"
;
this
.
tbxReportId
.
Size
=
new
System
.
Drawing
.
Size
(
162
,
21
);
this
.
tbxReportId
.
TabIndex
=
2
;
//
// label2
//
this
.
label2
.
AutoSize
=
true
;
this
.
label2
.
Location
=
new
System
.
Drawing
.
Point
(
18
,
47
);
this
.
label2
.
Name
=
"label2"
;
this
.
label2
.
Size
=
new
System
.
Drawing
.
Size
(
65
,
12
);
this
.
label2
.
TabIndex
=
1
;
this
.
label2
.
Text
=
"服务器地址"
;
//
// tbxServiceUrl
//
this
.
tbxServiceUrl
.
Location
=
new
System
.
Drawing
.
Point
(
88
,
44
);
this
.
tbxServiceUrl
.
Name
=
"tbxServiceUrl"
;
this
.
tbxServiceUrl
.
Size
=
new
System
.
Drawing
.
Size
(
162
,
21
);
this
.
tbxServiceUrl
.
TabIndex
=
2
;
this
.
tbxServiceUrl
.
Text
=
"http://k5.jst-gov.com"
;
//
// pgResult
//
this
.
pgResult
.
Dock
=
System
.
Windows
.
Forms
.
DockStyle
.
Right
;
this
.
pgResult
.
Location
=
new
System
.
Drawing
.
Point
(
619
,
0
);
this
.
pgResult
.
Name
=
"pgResult"
;
this
.
pgResult
.
Size
=
new
System
.
Drawing
.
Size
(
285
,
541
);
this
.
pgResult
.
TabIndex
=
3
;
//
// btnGenerateXlsx
//
this
.
btnGenerateXlsx
.
Location
=
new
System
.
Drawing
.
Point
(
29
,
187
);
this
.
btnGenerateXlsx
.
Name
=
"btnGenerateXlsx"
;
this
.
btnGenerateXlsx
.
Size
=
new
System
.
Drawing
.
Size
(
112
,
23
);
this
.
btnGenerateXlsx
.
TabIndex
=
0
;
this
.
btnGenerateXlsx
.
Text
=
"生成Xlsx文件"
;
this
.
btnGenerateXlsx
.
UseVisualStyleBackColor
=
true
;
this
.
btnGenerateXlsx
.
Click
+=
new
System
.
EventHandler
(
this
.
btnGenerateXlsx_Click
);
//
// label3
//
this
.
label3
.
AutoSize
=
true
;
this
.
label3
.
Location
=
new
System
.
Drawing
.
Point
(
18
,
146
);
this
.
label3
.
Name
=
"label3"
;
this
.
label3
.
Size
=
new
System
.
Drawing
.
Size
(
53
,
12
);
this
.
label3
.
TabIndex
=
1
;
this
.
label3
.
Text
=
"选择模板"
;
//
// tbxTemplateFileName
//
this
.
tbxTemplateFileName
.
Location
=
new
System
.
Drawing
.
Point
(
88
,
143
);
this
.
tbxTemplateFileName
.
Name
=
"tbxTemplateFileName"
;
this
.
tbxTemplateFileName
.
Size
=
new
System
.
Drawing
.
Size
(
162
,
21
);
this
.
tbxTemplateFileName
.
TabIndex
=
2
;
//
// btnSelectTemplateFile
//
this
.
btnSelectTemplateFile
.
Location
=
new
System
.
Drawing
.
Point
(
256
,
141
);
this
.
btnSelectTemplateFile
.
Name
=
"btnSelectTemplateFile"
;
this
.
btnSelectTemplateFile
.
Size
=
new
System
.
Drawing
.
Size
(
50
,
23
);
this
.
btnSelectTemplateFile
.
TabIndex
=
0
;
this
.
btnSelectTemplateFile
.
Text
=
"..."
;
this
.
btnSelectTemplateFile
.
UseVisualStyleBackColor
=
true
;
this
.
btnSelectTemplateFile
.
Click
+=
new
System
.
EventHandler
(
this
.
btnSelectTemplateFile_Click
);
//
// FrmMain
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
904
,
541
);
this
.
Controls
.
Add
(
this
.
pgResult
);
this
.
Controls
.
Add
(
this
.
tbxServiceUrl
);
this
.
Controls
.
Add
(
this
.
tbxTemplateFileName
);
this
.
Controls
.
Add
(
this
.
tbxReportId
);
this
.
Controls
.
Add
(
this
.
label2
);
this
.
Controls
.
Add
(
this
.
label3
);
this
.
Controls
.
Add
(
this
.
btnSelectTemplateFile
);
this
.
Controls
.
Add
(
this
.
btnGenerateXlsx
);
this
.
Controls
.
Add
(
this
.
label1
);
this
.
Controls
.
Add
(
this
.
btnGetReport
);
this
.
Name
=
"FrmMain"
;
this
.
Text
=
"Office测试"
;
this
.
ResumeLayout
(
false
);
this
.
PerformLayout
();
}
#
endregion
private
System
.
Windows
.
Forms
.
Button
btnGetReport
;
private
System
.
Windows
.
Forms
.
Label
label1
;
private
System
.
Windows
.
Forms
.
TextBox
tbxReportId
;
private
System
.
Windows
.
Forms
.
Label
label2
;
private
System
.
Windows
.
Forms
.
TextBox
tbxServiceUrl
;
private
System
.
Windows
.
Forms
.
PropertyGrid
pgResult
;
private
System
.
Windows
.
Forms
.
Button
btnGenerateXlsx
;
private
System
.
Windows
.
Forms
.
Label
label3
;
private
System
.
Windows
.
Forms
.
TextBox
tbxTemplateFileName
;
private
System
.
Windows
.
Forms
.
Button
btnSelectTemplateFile
;
}
}
Kivii.Client.OfficeSample/FrmMain.cs
0 → 100644
View file @
02f8cb74
using
Kivii.Client.OfficeSample.Entities
;
using
Kivii.Office.OpenXml.Templates
;
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel
;
using
System.Data
;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
using
System.Windows.Forms
;
namespace
Kivii.Client.OfficeSample
{
public
partial
class
FrmMain
:
Form
{
private
Contract
_contract
=
null
;
public
FrmMain
()
{
InitializeComponent
();
}
private
void
btnGetReport_Click
(
object
sender
,
EventArgs
e
)
{
JsonServiceClient
client
=
new
JsonServiceClient
(
tbxServiceUrl
.
Text
);
var
query
=
new
ContractQuery
();
query
.
ReportId
=
tbxReportId
.
Text
;
var
results
=
client
.
Get
(
query
);
if
(
results
.
Results
.
Count
<
1
)
{
MessageBox
.
Show
(
"未查询到报告"
);
return
;
}
_contract
=
results
.
Results
[
0
];
//显示各个属性值
pgResult
.
SelectedObject
=
_contract
;
}
private
void
btnSelectTemplateFile_Click
(
object
sender
,
EventArgs
e
)
{
OpenFileDialog
ofd
=
new
OpenFileDialog
();
ofd
.
Filter
=
"Excel模板文件|*.xlsx"
;
if
(
ofd
.
ShowDialog
()
!=
DialogResult
.
OK
)
return
;
tbxTemplateFileName
.
Text
=
ofd
.
FileName
;
}
private
void
btnGenerateXlsx_Click
(
object
sender
,
EventArgs
e
)
{
//先获取要保存的文件名称
SaveFileDialog
sfd
=
new
SaveFileDialog
();
sfd
.
Filter
=
"Excel文件|*.xlsx"
;
if
(
sfd
.
ShowDialog
()
!=
DialogResult
.
OK
)
return
;
var
saveFileName
=
sfd
.
FileName
;
//创建个模板引擎
var
template
=
new
TemplateExcel
();
template
.
Open
(
tbxTemplateFileName
.
Text
);
//打开模板文件
template
.
Bind
(
"contract"
,
_contract
);
//将数据绑定到模板中,注意contract在模板中这是这个变量名了
template
.
Fill
();
//填充模板
template
.
SaveAs
(
saveFileName
);
//最后另存当前的文件
}
}
}
Kivii.Client.OfficeSample/F
orm1
.resx
→
Kivii.Client.OfficeSample/F
rmMain
.resx
View file @
02f8cb74
File moved
Kivii.Client.OfficeSample/Kivii.Client.OfficeSample.csproj
View file @
02f8cb74
...
...
@@ -32,6 +32,10 @@
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"Kivii.Common.V4.0, Version=5.4.2019.8201, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Kivii.Common.5.4.2019.8201\lib\net40\Kivii.Common.V4.0.dll
</HintPath>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"Kivii.Office.OpenXml.V4.0, Version=5.4.2019.9100, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Kivii.Office.OpenXml.5.4.2019.9100\lib\net40\Kivii.Office.OpenXml.V4.0.dll
</HintPath>
<Private>
True
</Private>
...
...
@@ -48,16 +52,17 @@
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Form1.cs"
>
<Compile
Include=
"Entitis\Contract.cs"
/>
<Compile
Include=
"FrmMain.cs"
>
<SubType>
Form
</SubType>
</Compile>
<Compile
Include=
"F
orm1
.Designer.cs"
>
<DependentUpon>
F
orm1
.cs
</DependentUpon>
<Compile
Include=
"F
rmMain
.Designer.cs"
>
<DependentUpon>
F
rmMain
.cs
</DependentUpon>
</Compile>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<EmbeddedResource
Include=
"F
orm1
.resx"
>
<DependentUpon>
F
orm1
.cs
</DependentUpon>
<EmbeddedResource
Include=
"F
rmMain
.resx"
>
<DependentUpon>
F
rmMain
.cs
</DependentUpon>
</EmbeddedResource>
<EmbeddedResource
Include=
"Properties\Resources.resx"
>
<Generator>
ResXFileCodeGenerator
</Generator>
...
...
Kivii.Client.OfficeSample/Program.cs
View file @
02f8cb74
...
...
@@ -15,7 +15,7 @@ namespace Kivii.Client.OfficeSample
{
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
Application
.
Run
(
new
F
orm1
());
Application
.
Run
(
new
F
rmMain
());
}
}
}
Kivii.Client.OfficeSample/packages.config
View file @
02f8cb74
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
packages
>
<
package
id
=
"Kivii.Common"
version
=
"5.4.2019.8201"
targetFramework
=
"net40"
/>
<
package
id
=
"Kivii.Office.OpenXml"
version
=
"5.4.2019.9100"
targetFramework
=
"net40"
/>
</
packages
>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment