ISheet.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using Org.BouncyCastle.Asn1.Mozilla;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace InABox.Scripting
  10. {
  11. public class CellRange
  12. {
  13. public int FirstRow { get; set; }
  14. public int LastRow { get; set; }
  15. public int FirstColumn { get; set; }
  16. public int LastColumn { get; set; }
  17. public CellRange(int firstRow, int lastRow, int firstColumn, int lastColumn)
  18. {
  19. FirstRow = firstRow;
  20. LastRow = lastRow;
  21. FirstColumn = firstColumn;
  22. LastColumn = lastColumn;
  23. }
  24. }
  25. public interface IDataFormat {
  26. public short FormatIndex { get; }
  27. }
  28. public enum UnderlineType
  29. {
  30. None,
  31. Single,
  32. Double,
  33. SingleAccounting,
  34. DoubleAccounting
  35. }
  36. public interface IFont
  37. {
  38. public bool Bold { get; set; }
  39. public bool Italic { get; set; }
  40. public UnderlineType Underline { get; set; }
  41. public double FontSize { get; set; }
  42. public Color Colour { get; }
  43. }
  44. public interface ICellStyle
  45. {
  46. public ISpreadsheet Spreadsheet { get; }
  47. public IDataFormat DataFormat { get; set; }
  48. public IFont Font { get; }
  49. public Color Background { get; }
  50. public Color Foreground { get; }
  51. }
  52. public interface ISheet
  53. {
  54. public string Name { get; }
  55. int FirstRow { get; }
  56. int LastRow { get; }
  57. ISpreadsheet Spreadsheet { get; }
  58. IRow NewRow();
  59. IRow? GetRow(int row);
  60. /// <summary>
  61. /// Sets the column width with a certain number of characters.
  62. /// </summary>
  63. /// <param name="column"></param>
  64. /// <param name="charWidth"></param>
  65. /// <returns></returns>
  66. ISheet SetColumnWidth(int column, float charWidth);
  67. /// <summary>
  68. /// Gets the width of a column in characters. Returns float.MinValue if no width has been set.
  69. /// </summary>
  70. /// <param name="column"></param>
  71. /// <returns></returns>
  72. float GetColumnWidth(int column);
  73. /// <summary>
  74. /// Gets the height of a row in points.
  75. /// </summary>
  76. /// <param name="row"></param>
  77. /// <returns></returns>
  78. float GetRowHeight(int row);
  79. ISheet MergeCells(int firstRow, int lastRow, int firstColumn, int lastColumn);
  80. IEnumerable<CellRange> GetMergedCells();
  81. IEnumerable<IRow> Rows();
  82. IEnumerator<IRow> RowEnumerator();
  83. }
  84. public interface IRow
  85. {
  86. public int RowNumber { get; }
  87. int FirstColumn { get; }
  88. int LastColumn { get; }
  89. ISheet Sheet { get; }
  90. public ICell this[int column]
  91. {
  92. get { return GetCell(column); }
  93. }
  94. public string ExtractString(int column, bool uppercase = false);
  95. public DateTime ExtractDateTime(int column);
  96. public double? ExtractDouble(int column);
  97. public int GetColumn(string name, bool throwException = true);
  98. public ICell? GetCell(int column);
  99. public ICell NewCell(int column);
  100. public IEnumerable<ICell> Cells();
  101. }
  102. public interface ICell
  103. {
  104. IRow Row { get; }
  105. string GetValue();
  106. bool? GetBoolValue();
  107. double? GetDoubleValue();
  108. DateTime GetDateTimeValue();
  109. byte? GetByteValue();
  110. ICell SetValue(bool value);
  111. ICell SetValue(string value);
  112. ICell SetValue(double value);
  113. ICell SetValue(DateTime value);
  114. ICell SetValue(byte value);
  115. ICell SetBlank();
  116. ICellStyle GetStyle();
  117. ICell SetStyle(ICellStyle style);
  118. }
  119. public interface ISpreadsheet
  120. {
  121. public ISheet GetSheet(int index);
  122. public ISheet GetSheet(string name);
  123. /// <summary>
  124. /// Make a new sheet and add it to the spreadsheet
  125. /// </summary>
  126. /// <param name="name">The name of the new sheet</param>
  127. /// <returns>The new sheet</returns>
  128. public ISheet NewSheet(string name);
  129. /// <summary>
  130. /// Make a new sheet and add it to the spreadsheet
  131. /// </summary>
  132. /// <returns>The new sheet</returns>
  133. public ISheet NewSheet();
  134. public IEnumerable<ISheet> Sheets();
  135. public IEnumerator<ISheet> SheetEnumerator();
  136. public ICellStyle NewStyle();
  137. public IDataFormat GetDataFormat(string format);
  138. public void Write(FileStream file);
  139. public void Write(string filename, FileMode mode = FileMode.Create);
  140. }
  141. }