惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
罗磊的独立博客
SecWiki News
SecWiki News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
IT之家
IT之家
博客园 - 聂微东
T
The Exploit Database - CXSecurity.com
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Vercel News
Vercel News
G
GRAHAM CLULEY
D
DataBreaches.Net
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
SegmentFault 最新的问题
博客园_首页
雷峰网
雷峰网
T
Tenable Blog
Spread Privacy
Spread Privacy
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
J
Java Code Geeks
博客园 - Franky
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
C
CERT Recently Published Vulnerability Notes
T
Threatpost
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
T
The Blog of Author Tim Ferriss
V
Vulnerabilities – Threatpost
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
Security Latest
Security Latest
U
Unit 42
M
MIT News - Artificial intelligence
Y
Y Combinator Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
B
Blog
腾讯CDC

博客园 - greystar

LightSwitch OOB发布模式下 Title的处理 个性化lightswitch登录屏幕(附源码) LightSwitch登录界面如何设置背景 LightSwitch学习阶段疑难问答 使用 OfficeIntegration.Word 实现lightswitch导出WORD的功能(续) lightswitch如何实现文件批量上传功能 lightswitch自定义扩展实现示例教程 devexpress套餐中UploadControl实现自定义参数传递的例子 lightswitch中自动完成框与查询参数的联动效果 如何在LightSwitch中创建多栏自动完成的下拉框 自定义lightswitch主屏幕 SQL Server 2008中的MERGE(不仅仅是合并) 一段XSLT转换XML节点名的测试代码 SL相关的感想 使用LINQ取得已选中的CheckBox Batch Updating in Entity Framework 利用Register protocol实现网页调用桌面程序 路径标记语法 邮件合并中图片字段的处理
使用 OfficeIntegration.Word 实现lightswitch导出WORD的功能
greystar · 2011-11-01 · via 博客园 - greystar

从官网上下了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自动保存的功能。