ISheet.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. float GetDefaultRowHeight();
  80. ISheet MergeCells(int firstRow, int lastRow, int firstColumn, int lastColumn);
  81. IEnumerable<CellRange> GetMergedCells();
  82. IEnumerable<IRow> Rows();
  83. IEnumerator<IRow> RowEnumerator();
  84. }
  85. public interface IRow
  86. {
  87. public int RowNumber { get; }
  88. int FirstColumn { get; }
  89. int LastColumn { get; }
  90. ISheet Sheet { get; }
  91. public ICell this[int column]
  92. {
  93. get { return GetCell(column); }
  94. }
  95. public string ExtractString(int column, bool uppercase = false);
  96. public DateTime ExtractDateTime(int column);
  97. public double? ExtractDouble(int column);
  98. public int GetColumn(string name, bool throwException = true);
  99. public ICell? GetCell(int column);
  100. public ICell NewCell(int column);
  101. public IEnumerable<ICell> Cells();
  102. }
  103. public interface ICell
  104. {
  105. IRow Row { get; }
  106. string GetValue();
  107. bool? GetBoolValue();
  108. double? GetDoubleValue();
  109. DateTime GetDateTimeValue();
  110. byte? GetByteValue();
  111. ICell SetValue(bool value);
  112. ICell SetValue(string value);
  113. ICell SetValue(double value);
  114. ICell SetValue(DateTime value);
  115. ICell SetValue(byte value);
  116. ICell SetBlank();
  117. ICellStyle GetStyle();
  118. ICell SetStyle(ICellStyle style);
  119. }
  120. public interface ISpreadsheet
  121. {
  122. public ISheet GetSheet(int index);
  123. public ISheet GetSheet(string name);
  124. /// <summary>
  125. /// Make a new sheet and add it to the spreadsheet
  126. /// </summary>
  127. /// <param name="name">The name of the new sheet</param>
  128. /// <returns>The new sheet</returns>
  129. public ISheet NewSheet(string name);
  130. /// <summary>
  131. /// Make a new sheet and add it to the spreadsheet
  132. /// </summary>
  133. /// <returns>The new sheet</returns>
  134. public ISheet NewSheet();
  135. public IEnumerable<ISheet> Sheets();
  136. public IEnumerator<ISheet> SheetEnumerator();
  137. public ICellStyle NewStyle();
  138. public IDataFormat GetDataFormat(string format);
  139. public void Write(FileStream file);
  140. public void Write(string filename, FileMode mode = FileMode.Create);
  141. }
  142. }