使用 OfficeIntegration.Word 实现lightswitch导出WORD的功能

从官网上下了LightSwitch_Office_Integration_Pack_Extension 安装包,在LS属性中将扩展包加入到工程。

先制做一个WORD模板 ,示意如下:注意书签和控件名

将文件复制到LS的客户端工程中,并设为内嵌的资源。

在LS客户端需要导出WORD的地方,加一个命令按钮,生成相应的事件处理:

partial void GenerateDocument_Execute()
{
// Write your code here.
string path= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

Assembly ass = Assembly.GetExecutingAssembly();
Stream s = ass.GetManifestResourceStream(this.GetType(), "MonthPlan.docx");
byte[] bt = new byte[s.Length];
s.Read(bt, 0, bt.Length);
s.Close();
s.Dispose();
var fileName = this.WorkPlanHeads.SelectedItem.PlanYearMonth + "工作计划";
FileStream fs = new FileStream(path + "\\"+fileName+".docx", FileMode.Create);
fs.Write(bt, 0, bt.Length);
fs.Close();
fs.Dispose();

List<OfficeIntegration.ColumnMapping> planHeadColumn = new List<ColumnMapping>() {
new ColumnMapping("PlanYear","PlanYear"),
new ColumnMapping("PlanMonth","PlanMonth"),
new ColumnMapping("FillDate","FillDate")
};
var doc = OfficeIntegration.Word.GenerateDocument(path + "\\"+ fileName+".docx", this.WorkPlanHeads.SelectedItem, planHeadColumn);
List<string> detailsHeader = new List<string>() {
"" ,"TypeName","PlanContent","WorkEmp","WorkDept","PlanEndDate","Remark"
}; //要导到WORD中的对应的数据源中的列名,第一个为空,对应WORD中序号一列,这是在WORD模板中使用了自动编号的原因。

OfficeIntegration.Word.ExportEntityCollection(doc, "PlanDetail", 2, false, this.WorkPlanHeads.SelectedItem.WorkPlanDetails, detailsHeader);
OfficeIntegration.Word.SaveAsPDF(doc, path + "\\" + fileName + ".pdf", true);

}

接下来,进行调试,可以看到LS窗口中选中的数据被导入到WORD中。但是OfficeIntegration好象没有将生成的WORD自动保存的功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值