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

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 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自动保存的功能。