ISheet.cs 5.1 KB

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