Guest User

Untitled

a guest
Apr 9th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. // Create a new empty workbook with one worksheet.
  2. IWorkbook workbook = Factory.GetWorkbook();
  3. // Get the worksheet and change it's name to "Person".
  4. IWorksheet worksheet = workbook.Worksheets[0];
  5. worksheet.Name = "Colors";
  6. // Put "Hello World!" into A1.
  7. IRange a1 = worksheet.Cells["A1"];
  8. a1.Value = "Hello World!";
  9. a1.Font.Color = System.Drawing.Color.FromArgb(0x8C, 0xBE, 0x50);
  10. // Save the workbook as xls (Excel 97-2003 / Biff8) with default palette.
  11. //
  12. // This workbook will display the exact color in Excel 2007 and
  13. // SpreadsheetGear 2009, but will only display the closest available
  14. // palette indexed color in Excel 2003.
  15. workbook.SaveAs(@"C:tmpGreenDefaultPalette.xls", FileFormat.Excel8);
  16. // Save as xlsx / Open XML which will also display the exact color.
  17. workbook.SaveAs(@"C:tmpGreenDefaultPalette.xlsx", FileFormat.OpenXMLWorkbook);
  18. // Now, modify the palette and save. This workbook will display the exact
  19. // color in Excel 2003 as well as in SpreadsheetGear 2009 and Excel 2007.
  20. //
  21. // Note that modifying the palette will change the color of any cells which
  22. // already reference this palette indexed color - so be careful if you are
  23. // modifying pre-existing workbooks.
  24. workbook.Colors[0] = a1.Font.Color;
  25. workbook.SaveAs(@"C:tmpGreenModifiedPalette.xls", FileFormat.Excel8);
  26.  
  27. // Create a new empty workbook with one worksheet.
  28. IWorkbook workbook = Factory.GetWorkbook();
  29. // Get the worksheet and change it's name to "Person".
  30. IWorksheet worksheet = workbook.Worksheets[0];
  31. worksheet.Name = "Colors";
  32. // Put "Hello World!" into A1.
  33. IRange a1 = worksheet.Cells["A1"];
  34. a1.Value = "Hello World!";
  35. a1.Font.Color = System.Drawing.Color.FromArgb(0x8C, 0xBE, 0x50);
  36. // Save the workbook as xls (Excel 97-2003 / Biff8) with default palette.
  37. //
  38. // This workbook will display the exact color in Excel 2007 and
  39. // SpreadsheetGear 2009, but will only display the closest available
  40. // palette indexed color in Excel 2003.
  41. workbook.SaveAs(@"C:tmpGreenDefaultPalette.xls", FileFormat.Excel8);
  42. // Save as xlsx / Open XML which will also display the exact color.
  43. workbook.SaveAs(@"C:tmpGreenDefaultPalette.xlsx", FileFormat.OpenXMLWorkbook);
  44. // Now, modify the palette and save. This workbook will display the exact
  45. // color in Excel 2003 as well as in SpreadsheetGear 2009 and Excel 2007.
  46. //
  47. // Note that modifying the palette will change the color of any cells which
  48. // already reference this palette indexed color - so be careful if you are
  49. // modifying pre-existing workbooks.
  50. workbook.Colors[0] = a1.Font.Color;
  51. workbook.SaveAs(@"C:tmpGreenModifiedPalette.xls", FileFormat.Excel8);
Add Comment
Please, Sign In to add comment