WordToolTester.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ////############################################################
  2. //// https://github.com/yuzhengyang
  3. //// author:yuzhengyang
  4. ////############################################################
  5. //using Microsoft.Office.Interop.Word;
  6. //using System;
  7. //using System.Collections.Generic;
  8. //using System.Linq;
  9. //using Y.Utils.IOUtils.OfficeUtils;
  10. //namespace Y.Utils.Test
  11. //{
  12. // class WordToolTester
  13. // {
  14. // static void Main(string[] args)
  15. // {
  16. // int tsize = 5;
  17. // List<Dictionary<string, object>> test = new List<Dictionary<string, object>>();
  18. // for (int i = 0; i < 10; i++)
  19. // {
  20. // Dictionary<string, object> q = new Dictionary<string, object>();
  21. // q.Add("title", string.Format("第{0}题:{0}{0}{0}{0}", i));
  22. // q.Add("content", "长期从事电脑操作者,应多吃一些新鲜的蔬菜和水果,同时增加维生素A、B1、C、E的摄入。为预防角膜干燥、眼干涩、视力下降、甚至出现夜盲等,电 脑操作者应多吃富含维生素A的食物,如豆制品、鱼、牛奶、核桃、青菜、大白菜、空心菜、西红柿及新鲜水果等。");
  23. // q.Add("image", @"C:\Users\Administrator\Pictures\1.jpg");
  24. // test.Add(q);
  25. // }
  26. // WordTool report = new WordTool();
  27. // report.CreateNewDocument(@"F:\模板1.docx"); //模板路径
  28. // report.InsertValue("name", "测试考试");//在书签“Bookmark_value”处插入值
  29. // Table table = report.InsertTable("content", test.Count() * tsize, 1, 0); //在书签“Bookmark_table”处插入2行3列行宽最大的表
  30. // report.UseBorder(1, 0); //模板中第一个表格使用实线边框
  31. // for (int i = 0; i < test.Count(); i++)
  32. // {
  33. // //string picturePath = t["image"].ToString();
  34. // //report.InsertPicture("content", picturePath, 150, 150); //书签位置,图片路径,图片宽度,图片高度
  35. // //string content = t["content"].ToString();
  36. // //report.InsertText("content", content);
  37. // //string title = t["title"].ToString();
  38. // //report.InsertText("content", title);
  39. // report.InsertCell(table, 1 + (i * tsize), 1, test[i]["title"].ToString());//表名,行号,列号,值
  40. // report.InsertCell(table, 2 + (i * tsize), 1, test[i]["content"].ToString());//表名,行号,列号,值
  41. // report.InsertCell(table, 3 + (i * tsize), 1, test[i]["image"].ToString(), 150, 150, i + 1);//表名,行号,列号,值
  42. // }
  43. // report.SaveDocument(@"F:\doc1.doc"); //文档路径
  44. // Console.WriteLine("please input enter to exit.");
  45. // Console.ReadLine();
  46. // }
  47. // }
  48. //}