FindCell(Int32,Int32) Метод (XlsxDocumentSheet)
В этом разделе
Находит ячейку таблицы в указанном месте на листе.
Синтаксис
Parameters
- columnNumber
- Номер столбца.
- rowNumber
- Номер строки.
Return Value
Ячейка таблицы.
Пример
Вот C#/VB.NET код, который демонстрирует, как установить изображение штрихкода в XLSX документе (в примере используется шаблон документа)SetBarcodeImage_template.xlsx):
Public Shared Sub XlsxSetBarcodeImageExample()
Dim templateFilename As String = "SetBarcodeImage_template.xlsx"
Dim outFilename As String = "SetBarcodeImage.xlsx"
Dim outPdfFilename As String = "SetBarcodeImage.pdf"
' create XlsxDocumentEditor that allows to edit file "SetBarcodeImage_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)
' find cell with text "Invoice number:"
Dim cell As Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell = sheet.FindCell("Invoice number:")
' get barcode value as text of next row after "Invoice number:" cell
Dim barcodeValue As String = sheet.FindCell(cell.ColumnNumber, cell.RowNumber + 1).Text
' create and setup barcode generator
Dim barcodeGenerator As New Vintasoft.Barcode.BarcodeWriter()
barcodeGenerator.Settings.Barcode = Vintasoft.Barcode.BarcodeType.QR
barcodeGenerator.Settings.SetWidth(200)
barcodeGenerator.Settings.Value = barcodeValue
' generate barcode image
Using barcodeImage As New Vintasoft.Imaging.VintasoftImage(barcodeGenerator.GetBarcodeAsVintasoftBitmap(), True)
' crop barcode to the rectangular image
barcodeImage.Crop(New System.Drawing.Rectangle(0, 0, barcodeImage.Width, barcodeImage.Width))
' set barcode image to the DOCX image at index 0
editor.Images(0).SetImage(barcodeImage)
End Using
' 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 XlsxSetBarcodeImageExample()
{
string templateFilename = "SetBarcodeImage_template.xlsx";
string outFilename = "SetBarcodeImage.xlsx";
string outPdfFilename = "SetBarcodeImage.pdf";
// create XlsxDocumentEditor that allows to edit file "SetBarcodeImage_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];
// find cell with text "Invoice number:"
Vintasoft.Imaging.Office.OpenXml.Editor.Xlsx.XlsxDocumentSheetCell cell = sheet.FindCell("Invoice number:");
// get barcode value as text of next row after "Invoice number:" cell
string barcodeValue = sheet.FindCell(cell.ColumnNumber, cell.RowNumber + 1).Text;
// create and setup barcode generator
Vintasoft.Barcode.BarcodeWriter barcodeGenerator = new Vintasoft.Barcode.BarcodeWriter();
barcodeGenerator.Settings.Barcode = Vintasoft.Barcode.BarcodeType.QR;
barcodeGenerator.Settings.SetWidth(200);
barcodeGenerator.Settings.Value = barcodeValue;
// generate barcode image
using (Vintasoft.Imaging.VintasoftImage barcodeImage =
new Vintasoft.Imaging.VintasoftImage(barcodeGenerator.GetBarcodeAsVintasoftBitmap(), true))
{
// crop barcode to the rectangular image
barcodeImage.Crop(new System.Drawing.Rectangle(0, 0, barcodeImage.Width, barcodeImage.Width));
// set barcode image to the DOCX image at index 0
editor.Images[0].SetImage(barcodeImage);
}
// save changed document to a XLSX file
editor.Save(outFilename);
// export changed document to a PDF document
editor.Export(outPdfFilename);
}
}
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также