Commit 3dc49591 by 徐建业

同步

parents 47604be9 c789de18
......@@ -59,15 +59,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\DLL\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Spire.Doc, Version=7.12.23.4046, Culture=neutral, PublicKeyToken=663f351905198cb3, processorArchitecture=MSIL">
<HintPath>..\packages\Spire.Doc.7.12.23\lib\net46\Spire.Doc.dll</HintPath>
</Reference>
<Reference Include="Spire.License, Version=1.3.8.46, Culture=neutral, PublicKeyToken=b1144360237c8b3f, processorArchitecture=MSIL">
<HintPath>..\packages\Spire.Doc.7.12.23\lib\net46\Spire.License.dll</HintPath>
</Reference>
<Reference Include="Spire.Pdf, Version=5.12.16.18046, Culture=neutral, PublicKeyToken=663f351905198cb3, processorArchitecture=MSIL">
<HintPath>..\packages\Spire.Doc.7.12.23\lib\net46\Spire.Pdf.dll</HintPath>
</Reference>
<Reference Include="StackExchange.Redis, Version=1.2.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\StackExchange.Redis.1.2.6\lib\net46\StackExchange.Redis.dll</HintPath>
</Reference>
......@@ -85,12 +76,6 @@
<Reference Include="WorkFlow">
<HintPath>..\DLL\WorkFlow.dll</HintPath>
</Reference>
<Reference Include="Xceed.Document.NET, Version=1.5.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4, processorArchitecture=MSIL">
<HintPath>..\packages\DocX.1.5.0\lib\net40\Xceed.Document.NET.dll</HintPath>
</Reference>
<Reference Include="Xceed.Words.NET, Version=1.5.0.0, Culture=neutral, PublicKeyToken=3e4669d2f30244f4, processorArchitecture=MSIL">
<HintPath>..\packages\DocX.1.5.0\lib\net40\Xceed.Words.NET.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Chloe.Extension\DbActionBag.cs" />
......@@ -146,7 +131,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SqlHelper.cs" />
<Compile Include="VerCodeHelp.cs" />
<Compile Include="Word\CreateWordReport.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common.Unit.Word
{
public class CreateWordReport
{
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DocX" version="1.5.0" targetFramework="net46" />
<package id="JWT" version="5.2.2" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="Spire.Doc" version="7.12.23" targetFramework="net46" />
<package id="StackExchange.Redis" version="1.2.6" targetFramework="net46" />
</packages>
\ No newline at end of file
using G.Buss.BaseInfo.Services.SummarySVC;
using G.MES.API.App_Start;
using G.MES.DataModel;
using G.MES.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
namespace G.MES.API.Controllers
{
/// <summary>
/// 检测结果汇总表
/// </summary>
public class SummaryController : BasicController
{
private readonly SummarySvc svc = new SummarySvc();
/// <summary>
/// 导入检测结果
/// </summary>
/// <returns></returns>
[HttpPost]
[NoAuthAttribute]
public bool ImportSummary()
{
try
{
//LoginInfo user = GetLoginUser();
HttpPostedFile file = HttpContext.Current.Request.Files["Excel"];
return svc.ImportSummary(file);
}
catch (Exception e)
{
throw new Exception("表格导入错误" + e.Message);
}
}
/// <summary>
/// 获取检测结果所有数据(未分页,此功能暂时可能不需要)
/// </summary>
/// <returns></returns>
[HttpGet]
[NoAuthAttribute]
public List<Summary> GetSummaries()
{
return svc.GetSummaries();
}
}
}
\ No newline at end of file
......@@ -260,6 +260,7 @@
<Compile Include="Controllers\ExportWordController.cs" />
<Compile Include="Controllers\SampleControlController.cs" />
<Compile Include="Controllers\SampleTypeController.cs" />
<Compile Include="Controllers\SummaryController.cs" />
<Compile Include="Controllers\SystemController.cs" />
<Compile Include="Controllers\SystemLoggingController.cs" />
<Compile Include="Controllers\TargetedMedicineController.cs" />
......
......@@ -30,10 +30,11 @@
<add key="ExportFilePath" value="E:\Export" />
<add key="ImportTemplelatePath" value="192.168.6.131:10122\Template\" />
<add key="EnablePassWordStrength" value="1" />
<add key="TemplateDic" value="F:\Work\Project\报告系统\Git\ReportingSystemAPI\G.MES.API\Template\参考报告.docx" />
<add key="OutDic" value="F:\Work\Project\报告系统\Git\ReportingSystemAPI\G.MES.API\OutFile\" />
</appSettings>
<connectionStrings>
<add name="MainDB" connectionString="Data Source=.;Database=SYSMANAGE;User Id=sa;Password=123456" />
<add name="MainDB" connectionString="Data Source=47.96.124.15;Database=JCBB_MB;User Id=sa;Password=valtai" />
<add name="RedisExchangeHosts" connectionString="127.0.0.1:6379,allowadmin=true,password=123456" />
</connectionStrings>
<system.web>
......
......@@ -22,3 +22,54 @@ CREATE TABLE [dbo].[Chemotherapy](
```
alter table GeneCorrelation alter column [Type] varchar(50)
```
### 创建检查结果汇总表(Summary)表
```
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Summary](
[SummaryOID] [UNIQUEIDENTIFIER] NOT NULL,
[Gene] [VARCHAR](50) NULL,
[Position] [VARCHAR](50) NULL,
[Annotation] [TEXT] NULL,
[Abundance] [VARCHAR](50) NULL,
[Mutations] [VARCHAR](50) NULL,
[ParentOID] [UNIQUEIDENTIFIER] NOT NULL,
[SampleNumber] [VARCHAR](50) NULL,
[Sys_CreateBy] [UNIQUEIDENTIFIER] NULL,
[Sys_Create] [DATETIME] NULL,
CONSTRAINT [PK_Summary] PRIMARY KEY CLUSTERED
(
[SummaryOID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'基因' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'Gene'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'突变位置及类型' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'Position'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'结果注释' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'Annotation'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'丰度' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'Abundance'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'突变说明' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'Mutations'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'样本编号' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Summary', @level2type=N'COLUMN',@level2name=N'SampleNumber'
GO
```
......@@ -106,6 +106,7 @@
<Compile Include="Services\PMIDSVC\PMIDSVC.cs" />
<Compile Include="Services\SampleControlSVC\SampleControlSVC.cs" />
<Compile Include="Services\SampleTypeSVC\SampleTypeSVC.cs" />
<Compile Include="Services\SummarySVC\SummarySvc.cs" />
<Compile Include="Services\SystemLoggingAttribute\SystemLoggingAttribute.cs" />
<Compile Include="Services\SystemLoggingAttribute\SystenLoggingTableSVC.cs" />
<Compile Include="Services\TargetedMedicineReferencesSVC\TargetedMedicineReferencesSVC.cs" />
......
using Chloe;
using Chloe.SqlServer;
using Common.Unit;
using G.Buss.BaseInfo.ViewModel.ClientInfoModel;
using G.Buss.BaseInfo.ViewModel.CodeTableModel;
using G.Buss.BaseInfo.ViewModel.GeneCorrelationModel;
......@@ -10,6 +11,7 @@ using G.Buss.BaseInfo.ViewModel.TMBGradeRequestModel;
using G.MES.DataModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -24,27 +26,49 @@ namespace G.Buss.BaseInfo.Services.ExportWordSVC
/// 获取需要导出的受试者集合
/// </summary>
/// <param name="ClientInfosOID"></param>
public List<ClientInfoDetailModel> GetClirntInfo(List<Guid> ClientInfosOID)
public ClientInfoDetailModel GetClirntInfo(Guid requestModel)
{
return ClientInfo.DoGetClientInfoDetail(ClientInfosOID);
using (var context = new MsSqlContext(sqlConn))
{
ClientInfoDetailModel thisQueryModel = context.Query<ClientInfo>().Where(a => requestModel == a.ClientInfoOID)
.Select(a => new ClientInfoDetailModel
{
ClientInfoOID = a.ClientInfoOID,
Name = a.Name,
Sex = a.Sex,
IDCard = a.IDCard,
Birth = a.Birth,
SampleCode = a.SampleCode,
SampleType = a.SampleType,
Phone = a.Phone,
SampleDetection = a.SampleDetection,
TechnologyDetection = a.TechnologyDetection,
TumorsType = a.TumorsType,
TBM = a.TBM,
IsEssential = a.IsEssential,
ClinicalDiagnosis = a.ClinicalDiagnosis,
FamilyHistory = a.FamilyHistory,
PersonalHistory = a.PersonalHistory,
SamplingTime = a.SamplingTime
}).FirstOrDefault();
return thisQueryModel;
}
}
/// <summary>
/// 获取TMB等级说明
/// </summary>
public List<TMBGradeQueryModel> GetTMBLevel()
public List<TMBTable> GetTMBLevel()
{
using (var context = new MsSqlContext(sqlConn))
{
List<TMBGradeQueryModel> TMBGradeQuery = context.JoinQuery<TMBGrade, Sys_Organize>((TMBGrade, org) => new object[] {
List<TMBTable> TMBGradeQuery = context.JoinQuery<TMBGrade, Sys_Organize>((TMBGrade, org) => new object[] {
JoinType.LeftJoin,TMBGrade.SYS_ORG == org.Sys_OrganizeOID
}).Select((TMBGrade, org) => new TMBGradeQueryModel
}).Select((TMBGrade, org) => new TMBTable
{
TMBGradeOID = TMBGrade.TMBGradeOID,
Grade = TMBGrade.Grade,
Scope = TMBGrade.Scope,
Remark = TMBGrade.Remark,
ClassCode = org.ClassCode
Remark = TMBGrade.Remark
}).ToList();
return TMBGradeQuery;
}
......@@ -66,7 +90,6 @@ namespace G.Buss.BaseInfo.Services.ExportWordSVC
Remark = MISReport.Remark,
ClassCode = org.ClassCode
}).ToList();
int TotalNum = MISReportQuery.Count();
return MISReportQuery;
}
......@@ -74,9 +97,10 @@ namespace G.Buss.BaseInfo.Services.ExportWordSVC
/// <summary>
/// 获取检测结果
/// </summary>
public void GetCheckResult()
public DataTable GetCheckResult()
{
SqlHelper context = new SqlHelper();
return context.ExcuteDatatable("SELECT * FROM dbo.Summary ORDER BY CurrentIndex ASC", null);
}
/// <summary>
/// 获取化疗药物
......@@ -175,6 +199,28 @@ namespace G.Buss.BaseInfo.Services.ExportWordSVC
return GeneCorrelationQuery;
}
}
/// <summary>
/// 获取基因类型列表
/// </summary>
/// <returns></returns>
public List<SonCodeTableResponseModel> GetGeneTypeList()
{
using (var context = new MsSqlContext(sqlConn))
{
List<SonCodeTableResponseModel> AllSonDictionaryDirectory = context.Query<CodeValue>()
.Where(a => a.CodeTableID == "Code_GeneType")
.Select(a => new SonCodeTableResponseModel
{
CodeID = a.CodeID,
CodeName = a.CodeName,
OrderNo = a.OrderNo,
Reserved3 = a.Reserved3
}).ToList();
return AllSonDictionaryDirectory;
}
}
/// <summary>
/// 获取化药参考文献
/// </summary>
......
using G.MES.ViewModel;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using G.MES.DataModel;
using Chloe.SqlServer;
namespace G.Buss.BaseInfo.Services.SummarySVC
{
public class SummarySvc : BaseSvc
{
public List<Summary> GetSummaries()
{
using (var context = new MsSqlContext(sqlConn))
{
return context.Query<Summary>().ToList();
}
}
public bool ImportSummary(HttpPostedFile file)
{
try
{
DataTable table = RenderDataTableFromExcel(file.InputStream, 0, 0);
List<Summary> summaries = new List<Summary>();
List<string> SampleNumber = new List<string>();
Guid PreOID = Guid.Empty;
for (int i = 0; i < table.Rows.Count; i++)
{
Summary summary = new Summary();
Guid OID = Guid.NewGuid();
if (string.IsNullOrEmpty(table.Rows[i]["基因"].ToString()))
{
if (PreOID == Guid.Empty)
{
throw new Exception("excel第一行数据不能为空");
}
summary.ParentOID = PreOID;
summary.SummaryOID = OID;
summary.Gene = table.Rows[i]["基因"].ToString();
summary.Position = table.Rows[i]["突变位置及类型"].ToString();
summary.Annotation = table.Rows[i]["结果注释"].ToString();
summary.Abundance = table.Rows[i]["丰度"].ToString();
summary.Mutations = table.Rows[i]["突变说明"].ToString();
summary.SampleNumber = table.Rows[i]["样本编号"].ToString();
//summary.Sys_CreateBy = user.Sys_UserOID;
summary.Sys_Create = DateTime.Now;
summary.CurrentIndex = i;
}
else
{
summary.ParentOID = Guid.Empty;
summary.SummaryOID = OID;
summary.Gene = table.Rows[i]["基因"].ToString();
summary.Position = table.Rows[i]["突变位置及类型"].ToString();
summary.Annotation = table.Rows[i]["结果注释"].ToString();
summary.Abundance = table.Rows[i]["丰度"].ToString();
summary.Mutations = table.Rows[i]["突变说明"].ToString();
summary.SampleNumber = table.Rows[i]["样本编号"].ToString();
//summary.Sys_CreateBy = user.Sys_UserOID;
summary.Sys_Create = DateTime.Now;
summary.CurrentIndex = i;
PreOID = OID;
SampleNumber.Add(summary.SampleNumber);
}
summaries.Add(summary);
}
using (var context = new MsSqlContext(sqlConn))
{
List<Summary> summarie = context.Query<Summary>().Where(n => SampleNumber.Contains(n.SampleNumber)).ToList();
List<Guid> guids = summarie.Select(n => n.SummaryOID).ToList();
List<string> numbers = summarie.Select(n => n.SampleNumber).ToList();
//删除已存在的数据再重新插入
if (summarie.Any())
{
context.Delete<Summary>(m => numbers.Contains(m.SampleNumber) || guids.Contains(m.ParentOID));
}
context.InsertRange(summaries);
}
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, int SheetIndex, int HeaderRowIndex)
{
XSSFWorkbook workbook = new XSSFWorkbook(ExcelFileStream);
ISheet sheet = workbook.GetSheetAt(SheetIndex);
DataTable table = new DataTable();
IRow headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
table.Columns.Add(column);
}
int rowCount = sheet.LastRowNum;
for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
DataRow dataRow = table.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
{
if (row.GetCell(j) != null)
dataRow[j] = row.GetCell(j).ToString();
}
table.Rows.Add(dataRow);
}
ExcelFileStream.Close();
workbook = null;
sheet = null;
return table;
}
}
}
......@@ -37,6 +37,22 @@ namespace G.Buss.BaseInfo.ViewModel.TMBGradeRequestModel
}
public class TMBTable
{
/// <summary>
/// 范围
/// </summary>
public string Grade { get; set; }
/// <summary>
/// 等级
/// </summary>
public string Scope { get; set; }
/// <summary>
/// 说明
/// </summary>
public string Remark { get; set; }
}
public class TMBGradeQueryModel
{
/// <summary>
......
......@@ -115,6 +115,9 @@
<Compile Include="SampleType.cs">
<DependentUpon>DataTemplete.tt</DependentUpon>
</Compile>
<Compile Include="Summary.cs">
<DependentUpon>DataTemplete.tt</DependentUpon>
</Compile>
<Compile Include="SystemLogging.cs">
<DependentUpon>DataTemplete.tt</DependentUpon>
</Compile>
......
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码是根据模板生成的。
//
// 手动更改此文件可能会导致应用程序中发生异常行为。
// 如果重新生成代码,则将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------
namespace G.MES.DataModel
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Chloe.Annotations;
///<summary><summary>
[Serializable]
public partial class Summary : Core.BaseModel
{
///<summary><summary>
[ColumnAttribute(IsPrimaryKey = true)]
public virtual System.Guid SummaryOID { get;set; }
///<summary><summary>
public virtual string Gene { get;set; }
///<summary><summary>
public virtual string Position { get;set; }
///<summary><summary>
public virtual string Annotation { get;set; }
///<summary><summary>
public virtual string Abundance { get;set; }
///<summary><summary>
public virtual string Mutations { get;set; }
///<summary><summary>
public virtual System.Guid ParentOID { get;set; }
///<summary><summary>
public virtual string SampleNumber { get;set; }
///<summary><summary>
public virtual Nullable<System.Guid> Sys_CreateBy { get;set; }
///<summary><summary>
public virtual Nullable<System.DateTime> Sys_Create { get;set; }
///<summary><summary>
public virtual Nullable<int> CurrentIndex { get;set; }
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<!--是否启用token-->
<add key="EnableToken" value="1" />
<!--token的生成密匙-->
<add key="TokenSecret" value="gidea" />
<!--Redis的生成结构目录-->
<add key="RedisKey" value="ValTai:Common:" />
<add key="ApiPort" value="997" />
<!--终端补丁包的存放路径-->
<add key="ClientFilePath" value="F:\ClientFile" />
<!--导出问卷路径-->
<add key="ExportFilePath" value="E:\Export" />
<!--主网站的浏览文件的地址-->
<add key="MainWebSite" value="http://192.168.6.131:10222/" />
<!--录音文件路径-->
<add key="lywjurl" value="E:\GideaProject\TestUpLoadFile\ly" />
<!--回复图片路径-->
<add key="replyimage" value="D:\演示项目\新版万太云\Upload\img" />
<!--导出问卷路径-->
<add key="ExportFilePath" value="E:\Export" />
<add key="ImportTemplelatePath" value="192.168.6.131:10122\Template\" />
<add key="EnablePassWordStrength" value="1" />
<add key="TemplateDic" value="F:\Work\Project\报告系统\Git\ReportingSystemAPI\G.MES.API\Template\参考报告.docx" />
<add key="OutDic" value="F:\Work\Project\报告系统\Git\ReportingSystemAPI\G.MES.API\OutFile\" />
</appSettings>
<connectionStrings>
<add name="MainDB" connectionString="Data Source=47.96.124.15;Database=JCBB_MB;User Id=sa;Password=valtai" />
<add name="RedisExchangeHosts" connectionString="127.0.0.1:6379,allowadmin=true,password=123456" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.1.0" newVersion="2.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
......@@ -10,8 +10,9 @@ namespace UnitTestWord
[TestMethod]
public void TestMethod1()
{
OperationFunc operation = new OperationFunc();
operation.ReplaceText();
CreateWordReport report = new CreateWordReport();
report.CreateWord();
//OperationFunc.GetExcel();
}
}
}
......@@ -53,6 +53,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
......
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using NPOI.HPSF;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
namespace Nyd.Extend.Tool.NPOI
{
class NPOIHelper
{
private HSSFWorkbook hssfworkbook = new HSSFWorkbook();
private string xlsPath = "";
public NPOIHelper(string path)
{
xlsPath = path;
using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
{
hssfworkbook = new HSSFWorkbook(file);
}
}
#region 属性
public string XlsPath
{
get { return xlsPath; }
set { xlsPath = value; }
}
#endregion
#region 方法
/// <summary>
/// 创建一个空的Excel文档,指定sheet名
/// </summary>
/// <param name="xlspath">excel保存路径,默认为xls后缀名</param>
/// <param name="sheets">sheet名称</param>
public void CreateEmptyExcelFile(string xlspath, params string[] sheets)
{
InitializeWorkbook();
if (sheets.Count() > 0)
{
for (int i = 0; i < sheets.Count(); i++)
{
hssfworkbook.CreateSheet(sheets[i]);
}
}
else
{
hssfworkbook.CreateSheet("sheet1");
}
((HSSFSheet)hssfworkbook.GetSheetAt(0)).AlternativeFormula = false;
((HSSFSheet)hssfworkbook.GetSheetAt(0)).AlternativeExpression = false;
FileStream file = new FileStream(xlspath + ".xls", FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
#endregion
#region 私有方法
/// <summary>
/// 设置xls的信息
/// </summary>
private void InitializeWorkbook()
{
DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "NPOI Team";
hssfworkbook.DocumentSummaryInformation = dsi;
SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "NPOI Example";
hssfworkbook.SummaryInformation = si;
}
private void WriteToFile()
{
//Write the stream data of workbook to the root directory
FileStream file = new FileStream(xlsPath, FileMode.Create);
hssfworkbook.Write(file);
file.Close();
}
#endregion
/// <summary>
/// 写入数据,无格式
/// </summary>
/// <param name="Sheetindex">sheet索引</param>
/// <param name="value"></param>
public void SetCellValuesInXls(int Sheetindex, int RowIndex, int CellIndex, string value)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
sheet1.CreateRow(RowIndex).CreateCell(CellIndex).SetCellValue(value);
WriteToFile();
}
/// <summary>
/// 写入日期格式
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIndex"></param>
/// <param name="CellIndex"></param>
/// <param name="value"></param>
public void SetDateCellInXls(int Sheetindex, int RowIndex, int CellIndex, string date)
{
InitializeWorkbook();
ISheet sheet = hssfworkbook.GetSheetAt(Sheetindex);
// Create a row and put some cells in it. Rows are 0 based.
IRow row = sheet.CreateRow(RowIndex);
// Create a cell and put a date value in it. The first cell is not styled as a date.
ICell cell = row.CreateCell(CellIndex);
cell.SetCellValue(date);
ICellStyle cellStyle = hssfworkbook.CreateCellStyle();
cellStyle.DataFormat = hssfworkbook.CreateDataFormat().GetFormat("yyyy年m月d日");
cell.CellStyle = cellStyle;
//ICell cell2 = row.CreateCell(1);
//cell2.SetCellValue(new DateTime(2008, 5, 5));
//ICellStyle cellStyle2 = hssfworkbook.CreateCellStyle();
//IDataFormat format = hssfworkbook.CreateDataFormat();
//cellStyle2.DataFormat = format.GetFormat("yyyy年m月d日");
//cell2.CellStyle = cellStyle2;
//ICell cell3 = row.CreateCell(2);
//cell3.CellFormula = "DateValue(\"2005-11-11 11:11:11\")";
//ICellStyle cellStyle3 = hssfworkbook.CreateCellStyle();
//cellStyle3.DataFormat = HSSFDataFormat.GetBuiltinFormat("m/d/yy h:mm");
//cell3.CellStyle = cellStyle3;
WriteToFile();
}
/// <summary>
/// 给表格画边框
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIndex"></param>
/// <param name="CellIndex"></param>
public void SetBorderStyleInXls(int Sheetindex, int RowIndex, int CellIndex)
{
InitializeWorkbook();
ISheet sheet = hssfworkbook.GetSheetAt(Sheetindex);
// Create a row and put some cells in it. Rows are 0 based.
IRow row = sheet.GetRow(RowIndex);
// Create a cell and put a value in it.
ICell cell = row.GetCell(CellIndex);
// Style the cell with borders all around.
ICellStyle style = hssfworkbook.CreateCellStyle();
style.BorderBottom = BorderStyle.Thin;
style.BottomBorderColor = HSSFColor.Black.Index;
style.BorderLeft = BorderStyle.DashDotDot;
style.LeftBorderColor = HSSFColor.Green.Index;
style.BorderRight = BorderStyle.Hair;
style.RightBorderColor = HSSFColor.Blue.Index;
style.BorderTop = BorderStyle.MediumDashed;
style.TopBorderColor = HSSFColor.Orange.Index;
cell.CellStyle = style;
WriteToFile();
}
/// <summary>
/// 设置打印区域
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="Area">"A5:G20"</param>
public void SetPrintAreaInXls(int Sheetindex, string Area)
{
InitializeWorkbook();
hssfworkbook.SetPrintArea(Sheetindex, Area);
WriteToFile();
}
/// <summary>
/// 设置打印格式,默认为A4纸
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="Area"></param>
public void SetPrintFormatInXls(int Sheetindex)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
sheet1.SetMargin(MarginType.RightMargin, (double)0.5);
sheet1.SetMargin(MarginType.TopMargin, (double)0.6);
sheet1.SetMargin(MarginType.LeftMargin, (double)0.4);
sheet1.SetMargin(MarginType.BottomMargin, (double)0.3);
sheet1.PrintSetup.Copies = 3;
sheet1.PrintSetup.NoColor = true;
sheet1.PrintSetup.Landscape = true;
sheet1.PrintSetup.PaperSize = (short)PaperSize.A4;
sheet1.FitToPage = true;
sheet1.PrintSetup.FitHeight = 2;
sheet1.PrintSetup.FitWidth = 3;
sheet1.IsPrintGridlines = true;
WriteToFile();
}
/// <summary>
/// 设置表格的宽和高
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="width"></param>
/// <param name="height"></param>
public void SetWidthAndHeightInXls(int Sheetindex, int RowIdex, int CellIndex, int width, short height)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
//set the width of columns
sheet1.SetColumnWidth(CellIndex, width);
//set the width of height
sheet1.GetRow(RowIdex).Height = height;
sheet1.DefaultRowHeightInPoints = 50;
WriteToFile();
}
/// <summary>
/// 设置单元格对齐方式
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
/// <param name="Horizont">水平对齐方式:left,center,right,justify</param>
/// <param name="Vertical">垂直对齐方式:top,center,buttom,justify</param>
public void SetAlignmentInXls(int Sheetindex, int RowIdex, int CellIndex, string Horizont, string Vertical)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
IRow row = sheet1.GetRow(RowIdex);
ICellStyle style = hssfworkbook.CreateCellStyle();
if (Horizont == "left")
{
style.Alignment = HorizontalAlignment.Left;
}
else if (Horizont == "center")
{
style.Alignment = HorizontalAlignment.Center;
}
else if (Horizont == "right")
{
style.Alignment = HorizontalAlignment.Right;
}
else if (Horizont == "justify")
{
style.Alignment = HorizontalAlignment.Justify;
}
if (Vertical == "top")
{
style.VerticalAlignment = VerticalAlignment.Top;
}
else if (Vertical == "center")
{
style.VerticalAlignment = VerticalAlignment.Center;
}
else if (Vertical == "buttom")
{
style.VerticalAlignment = VerticalAlignment.Bottom;
}
else if (Vertical == "justify")
{
style.VerticalAlignment = VerticalAlignment.Justify;
}
style.Indention = 3;
row.GetCell(CellIndex).CellStyle = style;
WriteToFile();
}
/// <summary>
/// 放大缩小工作簿 根据 sub/den 进行缩放
/// </summary>
/// <param name="Sheetindex">要放大的sheet</param>
/// <param name="sub">比列的分子</param>
/// <param name="den">比列的分母</param>
public void ZoomSheet(int Sheetindex, int sub, int den)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
sheet1.SetZoom(sub, den); // 75 percent magnification
WriteToFile();
}
/// <summary>
/// 在单元格内使用多行存储数据
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
/// <param name="rows">使用的行数</param>
/// <param name="value">在换行的后面加上 \n</param>
public void UseNewlinesInCellsInXls(int Sheetindex, int RowIdex, int CellIndex, int rows, string value)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
//use newlines in cell
IRow row1 = sheet1.GetRow(RowIdex);
ICell cell1 = row1.GetCell(CellIndex);
//to enable newlines you need set a cell styles with wrap=true
ICellStyle cs = hssfworkbook.CreateCellStyle();
cs.WrapText = true;
cell1.CellStyle = cs;
row1.HeightInPoints = rows * sheet1.DefaultRowHeightInPoints;
cell1.SetCellValue(value);
WriteToFile();
}
/// <summary>
/// 单元格使用基础公式
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
/// <param name="Formula"></param>
public void UseBasicFormulaInXls(int Sheetindex, int RowIdex, int CellIndex, string Formula)
{
InitializeWorkbook();
ISheet s1 = hssfworkbook.GetSheetAt(Sheetindex);
//set A4=A2+A3,set D2=SUM(A2:C2);A5=cos(5)+sin(10)
s1.GetRow(RowIdex).GetCell(CellIndex).CellFormula = Formula;
WriteToFile();
}
/// <summary>
/// 冻结行,FreezeRow为要冻结的行
/// </summary>
/// <param name="Sheetindex"></param>
public void SplitAndFreezePanes(int Sheetindex, int FreezeRow)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
// Freeze just one row
sheet1.CreateFreezePane(0, FreezeRow);
WriteToFile();
}
/// <summary>
/// 缩放指定单元格字体
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
public void ShrinkToFitColumnInXls(int Sheetindex, int RowIdex, int CellIndex)
{
InitializeWorkbook();
ISheet sheet = hssfworkbook.GetSheetAt(Sheetindex);
IRow row = sheet.GetRow(RowIdex);
//create cell value
ICell cell1 = row.GetCell(CellIndex);
ICellStyle cellstyle1 = hssfworkbook.CreateCellStyle();
cellstyle1.ShrinkToFit = true;
WriteToFile();
}
/// <summary>
/// 将字体旋转指定角度
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
/// <param name="Angle"></param>
public void RotateTextInXls(int Sheetindex, int RowIdex, int CellIndex, short Angle)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
IRow row = sheet1.GetRow(RowIdex);
//set the style
ICellStyle style = hssfworkbook.CreateCellStyle();
style.Rotation = Angle;
row.GetCell(CellIndex).CellStyle = style;
WriteToFile();
}
/// <summary>
/// 向单元格中写入数字格式
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex"></param>
/// <param name="CellIndex"></param>
/// <param name="type">double,RMB,scentific,percent,phone,ChineseCapital,ChineseDate</param>
public void NumberFormatInXls(int Sheetindex, int RowIdex, int CellIndex, string type)
{
InitializeWorkbook();
ISheet sheet = hssfworkbook.GetSheetAt(Sheetindex);
//increase the width of Column A
sheet.SetColumnWidth(0, 5000);
//create the format instance
IDataFormat format = hssfworkbook.CreateDataFormat();
// Create a row and put some cells in it. Rows are 0 based.
ICell cell = sheet.GetRow(RowIdex).GetCell(CellIndex);
ICellStyle cellStyle = hssfworkbook.CreateCellStyle();
if (type == "double")
{
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00");
}
else if (type == "RMB")
{
cellStyle.DataFormat = format.GetFormat("¥#,##0");
}
else if (type == "scentific")
{
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00E+00");
}
else if (type == "percent")
{
cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%");
}
else if (type == "phone")//phone number format - "021-65881234"
{
cellStyle.DataFormat = format.GetFormat("000-00000000");
}
else if (type == "ChineseCapital") //Chinese capitalized character number - 壹贰叁 元
{
cellStyle.DataFormat = format.GetFormat("[DbNum2][$-804]0 元");
}
else if (type == "ChineseDate")
{
cellStyle.DataFormat = format.GetFormat("yyyy年m月d日");
}
cell.CellStyle = cellStyle;
WriteToFile();
}
/// <summary>
/// 将一个单元格赋予两个表格的乘积
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="RowIdex">要赋值的单元格行索引</param>
/// <param name="CellIndex">要赋值的单元格列索引</param>
/// <param name="targateRow1">第一个单元格的行</param>
/// <param name="targateCell1">第一个单元格的列</param>
/// <param name="targateRow2">第二个单元格的行</param>
/// <param name="targateCell2">第二个单元格的列</param>
public void MultplicationTableInXls(int Sheetindex, int RowIdex, int CellIndex, int targateRow1, int targateCell1,
int targateRow2, int targateCell2)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(Sheetindex);
IRow row = sheet1.GetRow(RowIdex);
string formula = GetCellPosition(targateRow1, targateCell1) + "*" + GetCellPosition(targateRow2, targateCell2);
row.CreateCell(CellIndex).CellFormula = formula;
WriteToFile();
}
public string GetCellPosition(int row, int col)
{
col = Convert.ToInt32('A') + col;
row = row + 1;
return ((char)col) + row.ToString();
}
/// <summary>
/// 合并单元格
/// </summary>
/// <param name="Sheetindex"></param>
/// <param name="firstRowIdex">起始单元格</param>
/// <param name="firstCellIndex"></param>
/// <param name="lastRowIdex">结束单元格</param>
/// <param name="lastCellIndex"></param>
public void MergeCellsInXls(int Sheetindex, int firstRowIdex, int firstCellIndex, int lastRowIdex, int lastCellIndex)
{
InitializeWorkbook();
ISheet sheet = hssfworkbook.GetSheetAt(Sheetindex);
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, 5));
CellRangeAddress region = new CellRangeAddress(firstRowIdex, lastRowIdex, firstCellIndex, lastCellIndex);
sheet.AddMergedRegion(region);
WriteToFile();
}
public string GetCellValue(int sheetIndex, int rowIndex, int cellIndex)
{
InitializeWorkbook();
ISheet sheet1 = hssfworkbook.GetSheetAt(sheetIndex);
ICell cell = sheet1.GetRow(rowIndex).GetCell(cellIndex);
return cell.StringCellValue;
}
#region 导入导出
/*
* DataTable table = new DataTable();
* MemoryStream ms = DataTableRenderToExcel.RenderDataTableToExcel(table) as MemoryStream;
* Response.AddHeader("Content-Disposition", string.Format("attachment; filename=Download.xls"));
* Response.BinaryWrite(ms.ToArray());
* ms.Close();
* ms.Dispose();
* if (this.fuUpload.HasFile)
* {
* DataTable table = DataTableRenderToExcel.RenderDataTableFromExcel(this.fuUpload.FileContent, 1, 0);
* this.gvExcel.DataSource = table;
* this.gvExcel.DataBind();
* }
*/
/// <summary>
/// Datatable导出Excel
/// </summary>
/// <param name="SourceTable"></param>
/// <returns></returns>
private static Stream RenderDataTableToExcel(DataTable SourceTable)
{
HSSFWorkbook workbook = new HSSFWorkbook();
MemoryStream ms = new MemoryStream();
ISheet sheet = workbook.CreateSheet();
IRow headerRow = sheet.CreateRow(0);
// handling header.
foreach (DataColumn column in SourceTable.Columns)
headerRow.CreateCell(column.Ordinal).SetCellValue(column.ColumnName);
// handling value.
int rowIndex = 1;
foreach (DataRow row in SourceTable.Rows)
{
IRow dataRow = sheet.CreateRow(rowIndex);
foreach (DataColumn column in SourceTable.Columns)
{
dataRow.CreateCell(column.Ordinal).SetCellValue(row[column].ToString());
}
rowIndex++;
}
workbook.Write(ms);
ms.Flush();
ms.Position = 0;
sheet = null;
headerRow = null;
workbook = null;
return ms;
}
/// <summary>
/// Datatable导出Excel
/// </summary>
/// <param name="SourceTable"></param>
/// <param name="FileName"></param>
public static void RenderDataTableToExcel(DataTable SourceTable, string FileName)
{
MemoryStream ms = RenderDataTableToExcel(SourceTable) as MemoryStream;
FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
byte[] data = ms.ToArray();
fs.Write(data, 0, data.Length);
fs.Flush();
fs.Close();
data = null;
ms = null;
fs = null;
}
/// <summary>
/// 导出excel为Datatable
/// </summary>
/// <param name="ExcelFileStream"></param>
/// <param name="SheetName"></param>
/// <param name="HeaderRowIndex"></param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, string SheetName, int HeaderRowIndex)
{
HSSFWorkbook workbook = new HSSFWorkbook(ExcelFileStream);
ISheet sheet = workbook.GetSheet(SheetName);
DataTable table = new DataTable();
IRow headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
table.Columns.Add(column);
}
int rowCount = sheet.LastRowNum;
for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
DataRow dataRow = table.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
dataRow[j] = row.GetCell(j).ToString();
}
ExcelFileStream.Close();
workbook = null;
sheet = null;
return table;
}
/// <summary>
/// 将Excel转换为Datatable
/// </summary>
/// <param name="ExcelFileStream"></param>
/// <param name="SheetIndex"></param>
/// <param name="HeaderRowIndex"></param>
/// <returns></returns>
public static DataTable RenderDataTableFromExcel(Stream ExcelFileStream, int SheetIndex, int HeaderRowIndex)
{
XSSFWorkbook workbook = new XSSFWorkbook(ExcelFileStream);
ISheet sheet = workbook.GetSheetAt(SheetIndex);
DataTable table = new DataTable();
IRow headerRow = sheet.GetRow(HeaderRowIndex);
int cellCount = headerRow.LastCellNum;
for (int i = headerRow.FirstCellNum; i < cellCount; i++)
{
DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
table.Columns.Add(column);
}
int rowCount = sheet.LastRowNum;
for (int i = (sheet.FirstRowNum + 1); i < sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
DataRow dataRow = table.NewRow();
for (int j = row.FirstCellNum; j < cellCount; j++)
{
if (row.GetCell(j) != null)
dataRow[j] = row.GetCell(j).ToString();
}
table.Rows.Add(dataRow);
}
ExcelFileStream.Close();
workbook = null;
sheet = null;
return table;
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xceed.Words.NET;
namespace WordByDocx.Word
{
public class CreateWordReport
{
//public static readonly string BaseDic = ConfigurationManager.AppSettings["TemplateDic"];
//public static readonly string OutDic = ConfigurationManager.AppSettings["OutDic"];
public static readonly string BaseDic = @"F:\Work\Project\报告系统\Git\ReportingSystemAPI\UnitTestWord\bin\Debug\template\参考报告.docx";
public static readonly string OutDic = @"F:\Work\Project\报告系统\Git\ReportingSystemAPI\UnitTestWord\bin\Debug\template\";
public string CreateWord()
{
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(BaseDic);
Guid guids = new Guid("7AFD11CC-259F-438B-B5DC-3469C891C5F0");
ReplaceText replaceText = new ReplaceText(document);
replaceText.ReplaceUserInfo(guids);
replaceText.ReplaceTMBTable();
replaceText.ReplaceMSITable();
replaceText.ReplaceTargetDrugReferences();
replaceText.ReplaceChemicalMedicineReferences();
replaceText.ReplaceGeneList();
replaceText.ReplaceSummary();
document.SaveToFile(OutDic + "out.docx");
using (var documentDocx = DocX.Load(OutDic + "out.docx"))
{
documentDocx.Paragraphs[0].ReplaceText("Evaluation Warning: The document was created with Spire.Doc for .NET.", "");
documentDocx.Save();
}
return "";
}
}
}
using G.Buss.BaseInfo.Services.ExportWordSVC;
using G.Buss.BaseInfo.ViewModel.ClientInfoModel;
using G.Buss.BaseInfo.ViewModel.CodeTableModel;
using G.Buss.BaseInfo.ViewModel.GeneCorrelationModel;
using G.Buss.BaseInfo.ViewModel.MISReportModel;
using G.Buss.BaseInfo.ViewModel.TMBGradeRequestModel;
using G.MES.DataModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WordByDocx.Word
{
/// <summary>
/// 自由操作固定的数据获取与释放
/// </summary>
public class GetData : IDisposable
{
private static readonly ReportDataSvc svc = new ReportDataSvc();
private static List<TMBTable> TMBs = null;
private static List<MISReportQueryModel> MSIs = null;
private static string TargetDrugReferences = string.Empty;
private static string ChemicalMedicineReferences = string.Empty;
/// <summary>
/// 获取受试者信息
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public static ClientInfoDetailModel GetUserInfo(Guid guid)
{
return svc.GetClirntInfo(guid);
}
/// <summary>
/// 获取检测结果
/// </summary>
/// <returns></returns>
public static DataTable GetSummary()
{
return svc.GetCheckResult();
}
/// <summary>
/// 获取TMB表格(这里不考虑线程的问题)
/// </summary>
public static List<TMBTable> GetTMBTable()
{
if (TMBs == null)
{
TMBs = svc.GetTMBLevel();
}
return TMBs;
}
/// <summary>
/// 获取TMB表格(这里不考虑线程的问题)
/// </summary>
public static List<MISReportQueryModel> GetMSITable()
{
if (MSIs == null)
{
MSIs = svc.GetMIS();
}
return MSIs;
}
/// <summary>
/// 获取基因列表
/// </summary>
/// <returns></returns>
public static List<GeneCorrelationQueryModel> GetGeneList()
{
return svc.GetGeneList();
}
/// <summary>
/// 获取基因类型列表
/// </summary>
/// <returns></returns>
public static List<SonCodeTableResponseModel> GetGeneTypeList()
{
return svc.GetGeneTypeList();
}
/// <summary>
/// 获取靶药文献
/// </summary>
/// <returns></returns>
public static string GetTargetDrugReferences()
{
if (string.IsNullOrEmpty(TargetDrugReferences))
{
TargetDrugReferences = svc.GetTargetDrugReferences();
}
return TargetDrugReferences;
}
/// <summary>
/// 获取化药文献
/// </summary>
/// <returns></returns>
public static string GetChemicalMedicineReferences()
{
if (string.IsNullOrEmpty(ChemicalMedicineReferences))
{
ChemicalMedicineReferences = svc.GetChemicalMdicineReferences();
}
return ChemicalMedicineReferences;
}
/// <summary>
/// 暂未做处理
/// </summary>
public void Dispose()
{
}
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nyd.Extend.Tool.NPOI;
using Spire.Doc;
using Spire.Doc.Documents;
using Xceed.Document.NET;
using Xceed.Words.NET;
namespace WordByDocx.Word
{
public class OperationFunc
public static class OperationFunc
{
private static string templateDic = AppDomain.CurrentDomain.BaseDirectory + "\\template\\";
public static void ReplaceFunc(this Spire.Doc.Document document, string oldString, string newString)
{
document.Replace(oldString, newString, false, true);
}
public static string ToLocalLongTime(this DateTime? dateTime)
{
if (dateTime == null)
{
return "";
}
return dateTime.ToString();
}
/// <summary>
/// 创建表格样式
/// </summary>
/// <param name="document"></param>
/// <param name="color"></param>
/// <param name="fontSizt"></param>
/// <returns></returns>
public static ParagraphStyle CreateTableStyle(this Spire.Doc.Document document, string textColor = "#000000", int fontSizt = 14)
{
Color C = System.Drawing.ColorTranslator.FromHtml(textColor);
ParagraphStyle style = new ParagraphStyle(document);
style.Name = "TableStyle";
style.CharacterFormat.FontSize = fontSizt;
style.CharacterFormat.TextColor = C;
document.Styles.Add(style);
return style;
}
public void ReplaceText()
public static readonly string BaseDic = @"F:\Work\Project\报告系统\Git\ReportingSystemAPI\UnitTestWord\bin\Debug\template\检测结果汇总表.xlsx";
public static void GetExcel()
{
Spire.Doc.Document document = new Spire.Doc.Document();
document.LoadFromFile(templateDic + "参考报告.docx");
document.Replace("#{Name}", "张三", false, true);
document.Replace("#{Phone}", "18895358744", false, true);
document.SaveToFile(templateDic + "out.docx");
using (var documentDocx = DocX.Load(templateDic + "out.docx"))
using (FileStream fileStream = new FileStream(BaseDic, FileMode.Open))
{
documentDocx.Paragraphs[0].ReplaceText("Evaluation Warning: The document was created with Spire.Doc for .NET.", "");
documentDocx.Save();
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
Stream stream = new MemoryStream(bytes);
DataTable table = NPOIHelper.RenderDataTableFromExcel(stream, 0, 0);
}
}
}
......
using G.Buss.BaseInfo.Services.ExportWordSVC;
using G.Buss.BaseInfo.ViewModel.ClientInfoModel;
using G.Buss.BaseInfo.ViewModel.CodeTableModel;
using G.Buss.BaseInfo.ViewModel.GeneCorrelationModel;
using G.Buss.BaseInfo.ViewModel.MISReportModel;
using G.Buss.BaseInfo.ViewModel.TMBGradeRequestModel;
using G.MES.DataModel;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WordByDocx.Word
{
public class ReplaceText
{
private Spire.Doc.Document document;
public ReplaceText(Spire.Doc.Document document)
{
this.document = document;
}
/// <summary>
/// 替换受试者基本信息
/// </summary>
public void ReplaceUserInfo(Guid guid)
{
ClientInfoDetailModel clientInfo = GetData.GetUserInfo(guid);
document.ReplaceFunc("#{Name}", clientInfo.Name);
document.ReplaceFunc("#{Sex}", clientInfo.Sex == 1 ? "男" : "女");
document.ReplaceFunc("#{Birthday}", clientInfo.Birth.ToLocalLongTime());
document.ReplaceFunc("#{IdCard}", clientInfo.IDCard);
document.ReplaceFunc("#{Phone}", clientInfo.Phone);
document.ReplaceFunc("#{SampleCode}", clientInfo.SampleCode);
document.ReplaceFunc("#{SampleType}", clientInfo.SampleType);
document.ReplaceFunc("#{SampleDetection}", clientInfo.SampleDetection);
document.ReplaceFunc("#{SamplingTime}", clientInfo.SamplingTime.ToLocalLongTime());
document.ReplaceFunc("#{TechnologyDetection}", clientInfo.TechnologyDetection);
document.ReplaceFunc("#{TumorsType}", clientInfo.TumorsType);
document.ReplaceFunc("#{TBM}", clientInfo.TBM);
document.ReplaceFunc("#{IsEssential}", clientInfo.IsEssential == true ? "是" : "否");
document.ReplaceFunc("#{ClinicalDiagnosis}", clientInfo.ClinicalDiagnosis);
document.ReplaceFunc("#{FamilyHistory}", clientInfo.FamilyHistory);
document.ReplaceFunc("#{PersonalHistory}", clientInfo.PersonalHistory);
}
/// <summary>
/// 替换检测结果
/// </summary>
public void ReplaceSummary()
{
DataTable summaries = GetData.GetSummary();
string[] heards = new string[] { "基因突变有对应药物提示", "突变位置及类型", "结果注释", "丰度" };
string[] tableHeards = new string[] { "Gene", "Position", "Annotation", "Abundance" };
Section section = document.Sections[0];
TextSelection selection = document.FindString("#{SummaryTable}", true, true);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);
Table table = section.AddTable(true);
table.ResetCells(summaries.Rows.Count + 1, heards.Length);
//填充数据与样式
for (int i = 0; i < heards.Length; i++)
{
TableRow Frow = table.Rows[0];
Frow.IsHeader = true;
Frow.Height = 30;
Frow.HeightType = TableRowHeightType.Exactly;
Frow.RowFormat.BackColor = Color.LightGoldenrodYellow;
Frow.Cells[i].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p3 = Frow.Cells[i].AddParagraph();
p3.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p3.AppendText(heards[i]);
}
bool mergeFlag = false;
Guid preOID = Guid.Empty;
for (int r = 0; r < summaries.Rows.Count; r++)
{
TableRow dataRow = table.Rows[r + 1];
dataRow.Height = 25;
for (int i = 0; i < tableHeards.Length; i++)
{
dataRow.Cells[i].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p = dataRow.Cells[i].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p.AppendText(summaries.Rows[r][tableHeards[i]].ToString());
}
}
body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);
}
/// <summary>
/// 替换TMB表格
/// </summary>
public void ReplaceTMBTable()
{
List<TMBTable> tMBs = GetData.GetTMBTable();
Section section = document.Sections[0];
TextSelection selection = document.FindString("#{TMBTable}", true, true);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);
Table table = section.AddTable(true);
table.ResetCells(tMBs.Count + 1, 3);
table.ApplyHorizontalMerge(0, 0, 2);
//填充数据与样式
TableRow Frow = table.Rows[0];
Frow.IsHeader = true;
Frow.Height = 30;
Frow.HeightType = TableRowHeightType.Exactly;
Frow.RowFormat.BackColor = Color.LimeGreen;
Frow.Cells[0].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p3 = Frow.Cells[0].AddParagraph();
p3.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p3.AppendText("TMB分为三个等级");
for (int r = 0; r < tMBs.Count; r++)
{
TableRow dataRow = table.Rows[r + 1];
dataRow.Height = 25;
//范围
dataRow.Cells[0].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p = dataRow.Cells[0].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p.AppendText(tMBs[r].Grade);
//等级
dataRow.Cells[1].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p1 = dataRow.Cells[1].AddParagraph();
p1.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p1.AppendText(tMBs[r].Scope);
//说明
dataRow.Cells[2].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p2 = dataRow.Cells[2].AddParagraph();
p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p2.AppendText(tMBs[r].Remark);
}
body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);
}
/// <summary>
/// 替换MSI表格
/// </summary>
public void ReplaceMSITable()
{
List<MISReportQueryModel> MSIS = GetData.GetMSITable();
Section section = document.Sections[0];
TextSelection selection = document.FindString("#{MSITable}", true, true);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);
Table table = section.AddTable(true);
table.ResetCells(MSIS.Count + 1, 3);
table.ApplyHorizontalMerge(0, 0, 2);
//填充数据与样式
TableRow Frow = table.Rows[0];
Frow.IsHeader = true;
Frow.Height = 30;
Frow.HeightType = TableRowHeightType.Exactly;
Frow.RowFormat.BackColor = Color.LimeGreen;
Frow.Cells[0].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p3 = Frow.Cells[0].AddParagraph();
p3.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p3.AppendText("MSI分为三个等级");
for (int r = 0; r < MSIS.Count; r++)
{
TableRow dataRow = table.Rows[r + 1];
dataRow.Height = 25;
//范围
dataRow.Cells[0].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p = dataRow.Cells[0].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p.AppendText(MSIS[r].Grade);
//等级
dataRow.Cells[1].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p1 = dataRow.Cells[1].AddParagraph();
p1.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p1.AppendText(MSIS[r].Scope);
//说明
dataRow.Cells[2].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p2 = dataRow.Cells[2].AddParagraph();
p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
p2.AppendText(MSIS[r].Remark);
}
body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);
}
/// <summary>
/// 替换基因列表
/// </summary>
public void ReplaceGeneList()
{
List<GeneCorrelationQueryModel> GeneList = GetData.GetGeneList();
Section section = document.Sections[0];
TextSelection selection = document.FindString("#{GeneList}", true, true);
TextRange range = selection.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
Body body = paragraph.OwnerTextBody;
int index = body.ChildObjects.IndexOf(paragraph);
Table table = section.AddTable(true);
double divisor = 6.00;
double ce = GeneList.Count / divisor;
int tableRows = (int)Math.Ceiling(ce);
table.ResetCells(tableRows, 6);
for (int r = 0; r < tableRows; r++)
{
TableRow dataRow = table.Rows[r];
dataRow.Height = 10;
for (int i = 0; i < 6; i++)
{
int currentIndex = 6 * r + i;
GeneCorrelationQueryModel gene = null;
if (currentIndex >= GeneList.Count)
{
break;
}
else
{
gene = GeneList[currentIndex];
dataRow.Cells[i].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
dataRow.Cells[i].CellFormat.BackColor = System.Drawing.ColorTranslator.FromHtml(gene.Color);
Paragraph p = dataRow.Cells[i].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
TextRange bg = p.AppendText(gene.GeneName);
bg.CharacterFormat.FontSize = 8;
}
}
}
body.ChildObjects.Remove(paragraph);
body.ChildObjects.Insert(index, table);
List<SonCodeTableResponseModel> GeneTypeList = GetData.GetGeneTypeList();
Section section2 = document.Sections[0];
TextSelection selection2 = document.FindString("#{GeneTypeList}", true, true);
TextRange range2 = selection2.GetAsOneRange();
Paragraph paragraph2 = range2.OwnerParagraph;
Body body2 = paragraph2.OwnerTextBody;
int index2 = body2.ChildObjects.IndexOf(paragraph2);
Table table2 = section2.AddTable(true);
table2.ResetCells(GeneTypeList.Count, 2);
for (int i = 0; i < GeneTypeList.Count; i++)
{
SonCodeTableResponseModel GeneType = GeneTypeList[i];
TableRow dataRow = table2.Rows[i];
dataRow.Cells[0].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
dataRow.Cells[0].CellFormat.BackColor = System.Drawing.ColorTranslator.FromHtml(GeneType.Reserved3);
Paragraph p2 = dataRow.Cells[0].AddParagraph();
p2.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
dataRow.Cells[1].CellFormat.VerticalAlignment = Spire.Doc.Documents.VerticalAlignment.Middle;
Paragraph p = dataRow.Cells[1].AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
TextRange bg = p.AppendText(GeneType.CodeName);
bg.CharacterFormat.FontSize = 10;
}
body2.ChildObjects.Remove(paragraph2);
body2.ChildObjects.Insert(index2, table2);
}
/// <summary>
/// 替换靶药文献
/// </summary>
public void ReplaceTargetDrugReferences()
{
string TargetDrugReferences = GetData.GetTargetDrugReferences();
TargetDrugReferences = TargetDrugReferences.Replace("<p>", "");
TargetDrugReferences = TargetDrugReferences.Replace("</p>", "");
document.ReplaceFunc("#{TargetDrugReferences}", TargetDrugReferences);
}
/// <summary>
/// 替换化药文献
/// </summary>
public void ReplaceChemicalMedicineReferences()
{
string ChemicalMedicineReferences = GetData.GetChemicalMedicineReferences();
ChemicalMedicineReferences = ChemicalMedicineReferences.Replace("<p>", "");
ChemicalMedicineReferences = ChemicalMedicineReferences.Replace("</p>", "");
document.ReplaceFunc("#{ChemicalMedicineReferences}", ChemicalMedicineReferences);
}
}
}
......@@ -31,6 +31,21 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.0.0.999, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.0.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="NPOI, Version=2.4.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.4.1\lib\net45\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML, Version=2.4.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.4.1\lib\net45\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net, Version=2.4.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.4.1\lib\net45\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats, Version=2.4.1.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.4.1\lib\net45\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="Spire.Doc, Version=7.12.21.4046, Culture=neutral, PublicKeyToken=663f351905198cb3, processorArchitecture=MSIL">
<HintPath>..\packages\Spire.Doc.7.12.21\lib\net46\Spire.Doc.dll</HintPath>
</Reference>
......@@ -41,7 +56,10 @@
<HintPath>..\packages\Spire.Doc.7.12.21\lib\net46\Spire.Pdf.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -58,17 +76,32 @@
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Unit\NPOIHelper.cs" />
<Compile Include="Word\CreateWordReport.cs" />
<Compile Include="Word\GetData.cs" />
<Compile Include="Word\OperationFunc.cs" />
<Compile Include="Word\ReplaceText.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="template\参考报告.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="template\检测结果汇总表.xlsx" />
</ItemGroup>
<ItemGroup>
<Folder Include="Data\" />
<Folder Include="Unit\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\G.MES.Business\G.BaseInfo\G.Buss.BaseInfo.csproj">
<Project>{6accaa60-f15a-49ac-a2ad-af68102357ae}</Project>
<Name>G.Buss.BaseInfo</Name>
</ProjectReference>
<ProjectReference Include="..\G.MES.DataModel\1.G.MES.DataModel.csproj">
<Project>{F5C4B2FE-C9DC-4C3A-BC3F-0AF46F0B783D}</Project>
<Name>1.G.MES.DataModel</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="NPOI" publicKeyToken="0df73ec7942b34e1" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.4.1.0" newVersion="2.4.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DocX" version="1.5.0" targetFramework="net46" />
<package id="NPOI" version="2.4.1" targetFramework="net46" />
<package id="SharpZipLib" version="1.0.0" targetFramework="net46" />
<package id="Spire.Doc" version="7.12.21" targetFramework="net46" />
</packages>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论