XLSX: Работа с строками ячеек на странице XLSX
В этом разделе
UI-контролы
SpreadsheetEditorControl и
WpfSpreadsheetEditorControl позволяют работать (добавлять, удалять, копировать, вырезать, вставлять, очищать, изменять размер, скрывать/показывать) со строками ячеек листа XLSX в настольном приложении (WinForms, WPF).
Строки ячеек можно изменять визуально с помощью мыши/клавиатуры или программно.
Добавление новой строки ячеек в лист XLSX.
Вот C#/VB.NET код, который демонстрирует, как добавить строку ячеек в лист XLSX:
public void AddCellRowToXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// insert new cell row before row "2"
spreadsheetVisualEditor.InsertEmptyRows();
}
Public Sub AddCellRowToXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' insert new cell row before row "2"
spreadsheetVisualEditor.InsertEmptyRows()
End Sub
Удаление строки ячеек листа XLSX
Вот C#/VB.NET код, который демонстрирует, как удалить строку ячеек на листе XLSX:
public void DeleteCellRowOnXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// delete the selected rows
spreadsheetVisualEditor.RemoveRows();
}
Public Sub DeleteCellRowOnXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' delete the selected rows
spreadsheetVisualEditor.RemoveRows()
End Sub
Копирование и вставка строка ячеек рабочего листа XLSX
Если вы хотите скопировать и вставить строку ячеек рабочего листа XLSX с помощью мыши, вам следует выполнить следующие шаги:
- Нажать левую кнопку мыши на заголовок строки, которую вы хотите скопировать.
- Нажать клавишу "Ctrl+C".
- Нажать левую кнопку мыши на заголовке строки, куда вы хотите вставить скопированную строку.
- Нажать клавишу "Ctrl+V".
Вот C#/VB.NET код, который демонстрирует, как скопировать и вставить строку ячеек рабочего листа XLSX:
public void CopyAndPasteCellRowOnXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// copy the selected cell row
spreadsheetVisualEditor.CopyCells();
// select the entire cell row "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("4:4");
// paste the content of row "2" into row "4"
spreadsheetVisualEditor.PasteCells();
}
Public Sub CopyAndPasteCellRowOnXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' copy the selected cell row
spreadsheetVisualEditor.CopyCells()
' select the entire cell row "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("4:4")
' paste the content of row "2" into row "4"
spreadsheetVisualEditor.PasteCells()
End Sub
Вырезание и вставка строки ячеек рабочего листа XLSX
Если вы хотите вырезать и вставить строку ячеек листа XLSX с помощью мыши, вам следует выполнить следующие шаги:
- Нажать левую кнопку мыши на заголовке строки, которую вы хочу вырезать.
- Нажать клавишу "Ctrl+X".
- Нажать левую кнопку мыши на заголовке строки, куда вы хотите вставить вырезанную строку.
- Нажать клавишу "Ctrl+V".
Вот C#/VB.NET код, который демонстрирует, как вырезать и вставить строку ячеек на листе XLSX:
public void CutAndPasteCellRowOnXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// cut the selected cell row
spreadsheetVisualEditor.CutCells();
// select the entire cell row "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("4:4");
// paste the content of row "2" into row "4"
spreadsheetVisualEditor.PasteCells();
}
Public Sub CutAndPasteCellRowOnXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' cut the selected cell row
spreadsheetVisualEditor.CutCells()
' select the entire cell row "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("4:4")
' paste the content of row "2" into row "4"
spreadsheetVisualEditor.PasteCells()
End Sub
Очистка содержимого строки ячейек листа XLSX
Если вы хотите очистить содержимое строки ячеек листа XLSX с помощью мыши, вам следует выполнить следующие шаги:
- Нажать левую кнопку мыши на заголовке строки, содержимое которой вы хотите очистить.
- Нажать клавишу "Del".
Вот C#/VB.NET код, который демонстрирует, как очистить содержимое строки ячеек рабочего листа XLSX:
public void ClearCellRowOnXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// clear the content of selected row
spreadsheetVisualEditor.ClearCellsContents();
}
Public Sub ClearCellRowOnXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' clear the content of selected row
spreadsheetVisualEditor.ClearCellsContents()
End Sub
Автоматический подгон высоты строки ячеек рабочего листа XLSX
Вот C#/VB.NET код, который демонстрирует, как автоматически подогнать высоту строки ячеек на листе XLSX:
public void AutoFitRowHeightOfXlsxCell(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2");
// autofit height of cell row
spreadsheetVisualEditor.AutoFitRowHeight();
}
Public Sub AutoFitRowHeightOfXlsxCell(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell row "2"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:2")
' autofit height of cell row
spreadsheetVisualEditor.AutoFitRowHeight()
End Sub
Скрытие/показ строки ячеек на листе XLSX
Вот C#/VB.NET код, который демонстрирует, как скрыть и показать строку ячейки листа XLSX:
public void HideAndShowCellOnXlsxWorksheet(Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl editorControl)
{
// get visual editor for spreadsheet document
Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor spreadsheetVisualEditor = editorControl.VisualEditor;
// select the entire cell rows "2", "3", "4", "5" and "6"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:6");
// hide the selected cell rows
spreadsheetVisualEditor.HideRows();
// select the entire cell rows "3" and "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("3:4");
// show the selected cell rows
spreadsheetVisualEditor.ShowRows();
}
Public Sub HideAndShowCellOnXlsxWorksheet(editorControl As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetEditorControl)
' get visual editor for spreadsheet document
Dim spreadsheetVisualEditor As Vintasoft.Imaging.Office.Spreadsheet.UI.SpreadsheetVisualEditor = editorControl.VisualEditor
' select the entire cell rows "2", "3", "4", "5" and "6"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("2:6")
' hide the selected cell rows
spreadsheetVisualEditor.HideRows()
' select the entire cell rows "3" and "4"
spreadsheetVisualEditor.SetFocusedAndSelectedCells("3:4")
' show the selected cell rows
spreadsheetVisualEditor.ShowRows()
End Sub