ISheet.cs 5.0 KB

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