XLSPrinter.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace PrintSolution
  7. {
  8. public class XLSPrinter : PrinterBase
  9. {
  10. private string xlsPath = string.Empty;
  11. public string XlsPath
  12. {
  13. get { return xlsPath; }
  14. set { xlsPath = value.Contains(":") ? value : AppDomain.CurrentDomain.BaseDirectory + value; }
  15. }
  16. private ArrayList paramList = new ArrayList();
  17. public ArrayList ParamList
  18. {
  19. get { return paramList; }
  20. set { paramList = value; }
  21. }
  22. private PictureInfo picInfo = new PictureInfo();
  23. public PictureInfo PicInfo
  24. {
  25. get { return picInfo; }
  26. set { picInfo = value; }
  27. }
  28. /// <summary>
  29. /// 打印方向设置 default0纵向 1横向
  30. /// </summary>
  31. public int Orientation
  32. {
  33. get { return base.PageSetup.Orientation; }
  34. set { base.PageSetup.Orientation = value; }
  35. }
  36. /// <summary>
  37. ///纸张设置
  38. /// </summary>
  39. public new PageSetup PageSetup
  40. {
  41. get { return base.PageSetup; }
  42. set { base.PageSetup = value; }
  43. }
  44. public XLSPrinter()
  45. {
  46. }
  47. public XLSPrinter(string xlsPath)
  48. {
  49. if (!xlsPath.Contains(":"))
  50. {
  51. xlsPath = AppDomain.CurrentDomain.BaseDirectory + xlsPath;
  52. }
  53. this.xlsPath = xlsPath;
  54. }
  55. public XLSPrinter(string xlsPath, ArrayList paramList)
  56. {
  57. if (!xlsPath.Contains(":"))
  58. {
  59. xlsPath = AppDomain.CurrentDomain.BaseDirectory + xlsPath;
  60. }
  61. this.xlsPath = xlsPath;
  62. this.paramList = paramList;
  63. }
  64. public void printExcel()
  65. {
  66. try
  67. {
  68. System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
  69. string printerName = printDoc.PrinterSettings.PrinterName;
  70. this.printExcel(xlsPath, printerName);
  71. }
  72. catch (Exception e)
  73. {
  74. throw e;
  75. }
  76. }
  77. protected override void paintPicByExcel(Microsoft.Office.Interop.Excel._Worksheet ws)
  78. {
  79. if (!string.IsNullOrEmpty(PicInfo.PicPath))
  80. {
  81. Microsoft.Office.Interop.Excel.Pictures pics = (Microsoft.Office.Interop.Excel.Pictures)ws.Pictures(missing);
  82. Microsoft.Office.Interop.Excel.Picture pic = pics.Insert(picInfo.PicPath, missing);
  83. pic.Left = picInfo.PicLeft;
  84. pic.Top = picInfo.PicTop;
  85. pic.Width = picInfo.PicWidth;
  86. pic.Height = picInfo.PicHeight;
  87. }
  88. }
  89. protected override void paintPicByEt(ET._Worksheet ws)
  90. {
  91. if (!string.IsNullOrEmpty(PicInfo.PicPath))
  92. {
  93. ET.Pictures pics = (ET.Pictures)ws.Pictures(missing);
  94. pics.Insert(picInfo.PicPath, missing);
  95. }
  96. }
  97. }
  98. }