WorksheetExtensions Class
Defines extension methods for the Worksheet interface.
You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these methods in production code.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Docs.v24.2.dll
NuGet Package: DevExpress.Document.Processor
#Declaration
#Remarks
To enable worksheet extensions, add a reference to the DevExpress.Docs.v24.2.dll assembly and explicitly import the DevExpress.Spreadsheet namespace into the code with the using directive (Imports in Visual Basic).
You can call extension methods in the same way as instance methods of the Worksheet object.
The following code snippet uses the Import extension method to insert data from a list into a worksheet.
The following code snippet imports data from a list of string objects:
byte[] imageBytes1 = File.ReadAllBytes("images//img.png");
byte[] imageBytes2 = File.ReadAllBytes("images//x-docserver.png");
// ...
Workbook workbook = new Workbook();
workbook.BeginUpdate();
try
{
Worksheet worksheet = workbook.Worksheets[0];
worksheet.Clear(worksheet.GetUsedRange());
worksheet.Cells["A1"].ColumnWidthInCharacters = 35;
worksheet.Cells["A1"].Value = "Import data from List vertically:";
ImportList(worksheet);
}
finally
{
workbook.EndUpdate();
workbook.SaveDocument("result.xlsx");
Process.Start(new ProcessStartInfo("result.xlsx") { UseShellExecute = true });
}
workbook.Dispose();
}
// ...
void ImportList(Worksheet worksheet)
{
// Create a List object containing string values.
List<string> cities = new List<string>
{
"New York",
"Rome",
"Beijing",
"Delhi"
};
List<byte[]> imageList = new List<byte[]>();
{
imageList.Add(imageBytes1);
imageList.Add(imageBytes2);
};
// Import the list into the worksheet and insert it vertically, starting with cell B1.
worksheet.Import(cities, 0, 1, true);
// Import the image list into the worksheet and insert it vertically
worksheet.Import(imageList, 0, 2, true, new DataImportOptions());
}
Refer to the following section for more examples on how to use the WorksheetExtensions methods to import data into a worksheet or export data from a worksheet to a data table: Import and Export Data