终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ExcelWrite.cs 1.8 KiB

10ヶ月前
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using BPASmartClient.DosingSystem.ViewModel;
  2. using Microsoft.Office.Interop.Excel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace BPASmartClient.DosingSystem.Model.ExcelModel
  11. {
  12. public class ExcelOperate
  13. {
  14. private volatile static ExcelOperate _Instance;
  15. public static ExcelOperate GetInstance => _Instance ?? (_Instance = new ExcelOperate());
  16. private ExcelOperate() { }
  17. /*public bool ExcelWrite(ObservableCollection<Allweight> allweights)
  18. {
  19. object misValue = System.Reflection.Missing.Value;
  20. Application app = new Application();
  21. Workbook wb = app.Workbooks.Add();
  22. Worksheet worksheet = (Worksheet)wb.Worksheets.get_Item(1);
  23. for (int i = 0; i < allweights.Count; i++)
  24. {
  25. worksheet.Cells[i+1,1] = allweights[i].RecipeName;
  26. }
  27. string filePath = @"C:\Users\刘耀文\Desktop\测试.xls";
  28. wb.SaveAs(filePath,XlFileFormat.xlWorkbookNormal,misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  29. wb.Close(true,misValue,misValue);
  30. app.Quit();
  31. return true;
  32. }
  33. public bool ExcelWriteTest()
  34. {
  35. Application app = new Application();
  36. Workbook wb = app.Workbooks.Add();
  37. Worksheet worksheet = (Worksheet)wb.Worksheets.get_Item(1);
  38. worksheet.Cells[1, 1] = "测试一下";
  39. string filePath = @"C:\Users\刘耀文\Desktop\测试.xls";
  40. wb.SaveAs(filePath);
  41. wb.Close();
  42. app.Quit();
  43. return true;
  44. }*/
  45. }
  46. }