Представляет собой редактор низкого уровня для XLSX документа.
Этот редактор предназначен для низкоуровневого редактирования документа XSLX, т.е. редактор позволяет редактировать документ как XLSX документ:
- Редактировать рабочие листы: Sheets, AddSheet(String), RemoveSheet(XlsxDocumentSheet)
- Добавить стили: AddEmptyStyle, AddStyle
- Установить свойства стиля: SetStyleBorders(Int32,CellBorders), XlsxDocumentEditor.SetStyleFillColor, SetStyleFontProperties(Int32,FontProperties), SetStyleName(Int32,String), SetStyleNumberFormat(Int32,String), SetStyleTextProperties(Int32,TextProperties)
- Изменение строк: GetRow(Int32), InsertRows(Int32,Int32), RemoveRows(Int32,Int32), FindRow(Int32), FindRow(String), Height, IsHidden, StyleIndex, InsertCopyAfterSelf, InsertCopyBeforeSelf
- Редактировать столбцы: GetColumnIsHidden(Int32), SetColumnsIsHidden(Int32,Int32,Boolean), GetColumnWidth(Int32), SetColumnsWidth(Int32,Int32,Double), SetColumnsIsHidden(Int32,Int32,Boolean), XlsxDocumentSheet.SetColumnsStyleIndex
- Редактировать ячейки: FindText(String), OpenXmlDocumentElement.FindTextNext, FindCell(String), FindCell(Int32,Int32)
- Изменить определенные имена: AddDefinedName(DefinedName), SetDefinedName(Int32,DefinedName), RemoveDefinedName(Int32)
- Редактирование изображений: AddImage(Stream,SheetDrawingLocation), Images, SetImage(Stream)
- Редактирование комментариев: MoveComment(Int32,Int32), RemoveComment(Int32,Int32), SetComment(CellComment,XlsxDocumentSheetCellCommentTransformType), SetCommentIsVisible(Int32,Int32,Boolean), SetCommentLocation(Int32,Int32,SheetDrawingLocation,XlsxDocumentSheetCellCommentTransformType)
Если вы хотите редактировать XLSX документ с помощью команд высокого уровня (редактировать XLSX документ как документ электронной таблицы), используйте SpreadsheetEditor класс.
Вот C#/VB.NET код, который демонстрирует, как найти и заменить текст в XLSX документе (в примере используется шаблон документа)FindAndReplaceText_template.xlsx):
Public Shared Sub XlsxFindAndReplaceTextExample()
Dim templateFilename As String = "FindAndReplaceText_template.xlsx"
Dim outFilename As String = "FindAndReplaceText.xlsx"
Dim outPdfFilename As String = "FindAndReplaceText.pdf"
' create XlsxDocumentEditor that allows to edit file "FindAndReplaceText_template.xlsx"
Using editor As New Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor(templateFilename)
' get first sheet in XLSX document
Dim sheet As Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheet = editor.Sheets(0)
' replace first occurrence of text "[field1]" by text "value1"
sheet("[field1]") = "value1"
' replace all occurrences of text "[field2]" by text "value2"
sheet.ReplaceText("[field2]", "value2")
' find text content that corresponds to the text "[field3]"
Dim field3Content As Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlTextContent = sheet.FindText("[field3]")
' change text in found text content
field3Content.Text = "value3"
' replace text "[multiline_field]" by multiline text
sheet("[multiline_field]") = vbLf & "line1" & vbLf & "line2" & vbLf & "line3"
' save changed document to a XLSX file
editor.Save(outFilename)
' export changed document to a PDF document
editor.Export(outPdfFilename)
End Using
End Sub
public static void XlsxFindAndReplaceTextExample()
{
string templateFilename = "FindAndReplaceText_template.xlsx";
string outFilename = "FindAndReplaceText.xlsx";
string outPdfFilename = "FindAndReplaceText.pdf";
// create XlsxDocumentEditor that allows to edit file "FindAndReplaceText_template.xlsx"
using (Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor editor =
new Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor(templateFilename))
{
// get first sheet in XLSX document
Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheet sheet = editor.Sheets[0];
// replace first occurrence of text "[field1]" by text "value1"
sheet["[field1]"] = "value1";
// replace all occurrences of text "[field2]" by text "value2"
sheet.ReplaceText("[field2]", "value2");
// find text content that corresponds to the text "[field3]"
Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlTextContent field3Content = sheet.FindText("[field3]");
// change text in found text content
field3Content.Text = "value3";
// replace text "[multiline_field]" by multiline text
sheet["[multiline_field]"] = "\nline1\nline2\nline3";
// save changed document to a XLSX file
editor.Save(outFilename);
// export changed document to a PDF document
editor.Export(outPdfFilename);
}
}
System.Object
 Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentEditor
   Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentEditor
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5