求一个导出word 方案

橙色阳光 2014-08-20 09:34:10
需求:
数据已经都在数据库中,有文字,图片;手头已经拿到导出word效果的格式.
用的是C#开发.再加个界面导出WORD就好了.
问的是排版有那么点复杂,导出word用什么方法比较好. 有什么控件/现场的方法吗?
...全文
364 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
txwg_1725693464 2014-08-21
  • 打赏
  • 举报
回复
把Word文档中的表格数据导入到SQL Server数据库中 private Word.Application G_wa;//定义Word应用程序字段 private object G_missing = //定义G_missing字段并添加引用 System.Reflection.Missing.Value; private Thread G_th;//定义线程字段 private List<InstanceClass> G_List_InstanceClass = //定义数据集合字段并赋值 new List<InstanceClass>(); private void btn_display_Click(object sender, EventArgs e) { btn_display.Enabled = false; ThreadPool.QueueUserWorkItem(//开始线程池 (pp) =>//使用lambda表达式 { G_wa = new Microsoft.Office.Interop.Word.Application();//创建应用程序对象 G_wa.Visible = true;//CodeGo.net/ object P_Path = Directory.GetCurrentDirectory() + @"\Word.doc"; Word.Document P_Document = G_wa.Documents.Open(//打开Word文档 ref P_Path, ref G_missing, ref G_missing, ref G_missing , ref G_missing, ref G_missing, ref G_missing, ref G_missing , ref G_missing, ref G_missing, ref G_missing, ref G_missing , ref G_missing, ref G_missing, ref G_missing, ref G_missing); TrackData();//将Word数据更新到SQL }); }
熙风 2014-08-20
  • 打赏
  • 举报
回复
引用 5 楼 sat472291519 的回复:
[quote=引用 3 楼 happy09li 的回复:] 把word的格式用html显示,然后用流导出
 
string  path=@"C:\Documents and Settings\Administrator\桌面\2.doc";
    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);  
            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));  
            string html = @"C:\Documents and Settings\Administrator\桌面\1.html";  
            sw.WriteLine(File.ReadAllText(html));  
            sw.Close();  
到excel 也可以这样
能有更详细的案例吗? 因为您这种方式我没有做过.光一句"把word的格式用html显示,然后用流导出" 我很茫然.[/quote] word要显示什么样,就用html显示什么样
threenewbee 2014-08-20
  • 打赏
  • 举报
回复
引用 6 楼 sat472291519 的回复:
[quote=引用 4 楼 caozhy 的回复:] 先用word做好一个文档,排版好,预留下数据填充的位置,作为模板。导出的时候复制一份模板,在此基础上填入数据,保存。
哇靠,这思路很不错!!! 问题是代码怎么去实现呢? 复制拷贝简单的. 然后 我怎么定位,A数据定位填充到哪一行呢,哪个字后面呢?有先例吗?[/quote] 你可以加一些特殊的文本作为特征来定位。这样你通过遍历就能找到它,也知道在哪里添加了。
橙色阳光 2014-08-20
  • 打赏
  • 举报
回复
引用 4 楼 caozhy 的回复:
先用word做好一个文档,排版好,预留下数据填充的位置,作为模板。导出的时候复制一份模板,在此基础上填入数据,保存。
哇靠,这思路很不错!!! 问题是代码怎么去实现呢? 复制拷贝简单的. 然后 我怎么定位,A数据定位填充到哪一行呢,哪个字后面呢?有先例吗?
橙色阳光 2014-08-20
  • 打赏
  • 举报
回复
引用 3 楼 happy09li 的回复:
把word的格式用html显示,然后用流导出
 
string  path=@"C:\Documents and Settings\Administrator\桌面\2.doc";
    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);  
            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));  
            string html = @"C:\Documents and Settings\Administrator\桌面\1.html";  
            sw.WriteLine(File.ReadAllText(html));  
            sw.Close();  
到excel 也可以这样
能有更详细的案例吗? 因为您这种方式我没有做过.光一句"把word的格式用html显示,然后用流导出" 我很茫然.
threenewbee 2014-08-20
  • 打赏
  • 举报
回复
先用word做好一个文档,排版好,预留下数据填充的位置,作为模板。导出的时候复制一份模板,在此基础上填入数据,保存。
熙风 2014-08-20
  • 打赏
  • 举报
回复
把word的格式用html显示,然后用流导出
 
string  path=@"C:\Documents and Settings\Administrator\桌面\2.doc";
    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write);  
            StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("gb2312"));  
            string html = @"C:\Documents and Settings\Administrator\桌面\1.html";  
            sw.WriteLine(File.ReadAllText(html));  
            sw.Close();  
到excel 也可以这样
LoveNet_ 2014-08-20
  • 打赏
  • 举报
回复
new Application
CUIWEI19871116 2014-08-20
  • 打赏
  • 举报
回复
用aspose.word 在word要插入数据的地方建好书签 然后程序控制向书签里放相应的数据

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧