NanoXLSX.Core 3.0.0-rc.3
Loading...
Searching...
No Matches
Shortener.cs
1/*
2 * NanoXLSX is a small .NET library to generate and read XLSX (Microsoft Excel 2007 or newer) files in an easy and native way
3 * Copyright Raphael Stoeckli © 2025
4 * This library is licensed under the MIT License.
5 * You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6 */
7
10
11namespace NanoXLSX
12{
18 public class Shortener
19 {
20 private Worksheet currentWorksheet;
21 private readonly Workbook workbookReference;
22
27 public Shortener(Workbook reference)
28 {
29 this.workbookReference = reference;
30 this.currentWorksheet = reference.CurrentWorksheet;
31 }
32
37 public void SetCurrentWorksheet(Worksheet worksheet)
38 {
39 workbookReference.SetCurrentWorksheet(worksheet);
40 currentWorksheet = worksheet;
41 }
42
47 internal void SetCurrentWorksheetInternal(Worksheet worksheet)
48 {
49 currentWorksheet = worksheet;
50 }
51
57 public void Value(object cellValue)
58 {
59 NullCheck();
60 currentWorksheet.AddNextCell(cellValue);
61 }
62
69 public void Value(object cellValue, Style style)
70 {
71 NullCheck();
72 currentWorksheet.AddNextCell(cellValue, style);
73 }
74
80 public void Formula(string cellFormula)
81 {
82 NullCheck();
83 currentWorksheet.AddNextCellFormula(cellFormula);
84 }
85
92 public void Formula(string cellFormula, Style style)
93 {
94 NullCheck();
95 currentWorksheet.AddNextCellFormula(cellFormula, style);
96 }
97
101 public void Down()
102 {
103 NullCheck();
104 currentWorksheet.GoToNextRow();
105 }
106
113 public void Down(int numberOfRows, bool keepColumnPosition = false)
114 {
115 NullCheck();
116 currentWorksheet.GoToNextRow(numberOfRows, keepColumnPosition);
117 }
118
123 public void Up()
124 {
125 NullCheck();
126 currentWorksheet.GoToNextRow(-1);
127 }
128
135 public void Up(int numberOfRows, bool keepColumnPosition = false)
136 {
137 NullCheck();
138 currentWorksheet.GoToNextRow(-1 * numberOfRows, keepColumnPosition);
139 }
140
144 public void Right()
145 {
146 NullCheck();
147 currentWorksheet.GoToNextColumn();
148 }
149
155 public void Right(int numberOfColumns, bool keepRowPosition = false)
156 {
157 NullCheck();
158 currentWorksheet.GoToNextColumn(numberOfColumns, keepRowPosition);
159 }
160
165 public void Left()
166 {
167 NullCheck();
168 currentWorksheet.GoToNextColumn(-1);
169 }
170
177 public void Left(int numberOfColumns, bool keepRowRowPosition = false)
178 {
179 NullCheck();
180 currentWorksheet.GoToNextColumn(-1 * numberOfColumns, keepRowRowPosition);
181 }
182
186 private void NullCheck()
187 {
188 if (currentWorksheet == null)
189 {
190 throw new WorksheetException("No worksheet was defined");
191 }
192 }
193
194
195 }
196}
Class for exceptions regarding worksheet incidents.
void Right()
Moves the cursor one column to the right.
Definition Shortener.cs:144
void Value(object cellValue)
Sets a value into the current cell and moves the cursor to the next cell (column or row depending on ...
Definition Shortener.cs:57
void SetCurrentWorksheet(Worksheet worksheet)
Sets the worksheet accessed by the shortener.
Definition Shortener.cs:37
void Up(int numberOfRows, bool keepColumnPosition=false)
Moves the cursor the number of defined rows up.
Definition Shortener.cs:135
void Down(int numberOfRows, bool keepColumnPosition=false)
Moves the cursor the number of defined rows down.
Definition Shortener.cs:113
void Left()
Moves the cursor one column to the left.
Definition Shortener.cs:165
void Formula(string cellFormula)
Sets a formula into the current cell and moves the cursor to the next cell (column or row depending o...
Definition Shortener.cs:80
void Up()
Moves the cursor one row up.
Definition Shortener.cs:123
void Right(int numberOfColumns, bool keepRowPosition=false)
Moves the cursor the number of defined columns to the right.
Definition Shortener.cs:155
void Formula(string cellFormula, Style style)
Sets a formula with style into the current cell and moves the cursor to the next cell (column or row ...
Definition Shortener.cs:92
void Down()
Moves the cursor one row down.
Definition Shortener.cs:101
Shortener(Workbook reference)
Constructor with workbook reference.
Definition Shortener.cs:27
void Value(object cellValue, Style style)
Sets a value with style into the current cell and moves the cursor to the next cell (column or row de...
Definition Shortener.cs:69
void Left(int numberOfColumns, bool keepRowRowPosition=false)
Moves the cursor the number of defined columns to the left.
Definition Shortener.cs:177
Class representing a Style with sub classes within a style sheet. An instance of this class is only a...
Definition Style.cs:18
Class representing a workbook.
Definition Workbook.cs:23
Worksheet CurrentWorksheet
Gets the current worksheet.
Definition Workbook.cs:64
Class representing a worksheet of a workbook.
Definition Worksheet.cs:26