You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

82 lines
2.1 KiB

  1. using Spire.Xls;
  2. using System;
  3. using Learun.Util;
  4. using Spire.Doc;
  5. using System.IO;
  6. namespace Learun.Application.OA.File.FilePreview
  7. {
  8. public class FilePreviewBLL:FilePreviewIBLL
  9. {
  10. /// <summary>
  11. /// 获取EXCEL数据
  12. /// <summary>
  13. /// <returns></returns>
  14. public void GetExcelData(string path)
  15. {
  16. try
  17. {
  18. // load Excel file
  19. Workbook workbook = new Workbook();
  20. workbook.LoadFromFile(path);
  21. workbook.SaveToFile(path.Substring(0, path.LastIndexOf(".")) + ".pdf", Spire.Xls.FileFormat.PDF);
  22. }
  23. catch (Exception ex)
  24. {
  25. if (ex is ExceptionEx)
  26. {
  27. throw;
  28. }
  29. else
  30. {
  31. throw ExceptionEx.ThrowBusinessException(ex);
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// 获取Word数据
  37. /// <summary>
  38. /// <returns></returns>
  39. public void GetWordData(string path)
  40. {
  41. try
  42. {
  43. Document document = new Document();
  44. document.LoadFromFile(path);
  45. document.SaveToFile(path.Substring(0, path.LastIndexOf(".")) + ".pdf", Spire.Doc.FileFormat.PDF);
  46. }
  47. catch (Exception ex)
  48. {
  49. if (ex is ExceptionEx)
  50. {
  51. throw;
  52. }
  53. else
  54. {
  55. throw ExceptionEx.ThrowBusinessException(ex);
  56. }
  57. }
  58. }
  59. /// <summary>
  60. /// 获取Word数据
  61. /// <summary>
  62. /// <returns></returns>
  63. public void GetPptData(string path)
  64. {
  65. try
  66. {
  67. Document document = new Document();
  68. document.LoadFromFile(path);
  69. document.SaveToFile(path.Substring(0, path.LastIndexOf(".")) + ".pdf", Spire.Doc.FileFormat.PDF);
  70. }
  71. catch (Exception)
  72. {
  73. throw (new Exception("文件丢失"));
  74. }
  75. }
  76. }
  77. }