Commit 02f8cb74 by 施晓雨

1

parent 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
}
}
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();
}
}
}
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;
}
}
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);//最后另存当前的文件
}
}
}
......@@ -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="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
<Compile Include="FrmMain.Designer.cs">
<DependentUpon>FrmMain.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
<EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
......
......@@ -15,7 +15,7 @@ namespace Kivii.Client.OfficeSample
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
Application.Run(new FrmMain());
}
}
}
<?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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment