[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Workbook.ImportData

ImportData Method

ImportData(string, string)

Import all the data of the specified source of the file.

Declaration
public static object[,] ImportData(string fileName, string sourceName)
Public Shared Function ImportData(fileName As String, sourceName As String) As Object(,)
Parameters
Type Name Description
string fileName

The path and name for the file.

string sourceName

The name of the data source. The source name could be:
worksheet "Sheet1"
table "Sheet1!Table1"
range "Sheet1!A1:C5"

Returns
Type Description
object[,]

An array for the data.

ImportData(string, string, int, int, int, int)

Import the data of a specified range from a file.

Declaration
public static object[,] ImportData(string fileName, string worksheetName, int row, int column, int rowCount, int columnCount)
Public Shared Function ImportData(fileName As String, worksheetName As String, row As Integer, column As Integer, rowCount As Integer, columnCount As Integer) As Object(,)
Parameters
Type Name Description
string fileName

The path and name for the file.

string worksheetName

The name of the worksheet.

int row

The first row of the range.

int column

The first column of the range.

int rowCount

The count of the rows.

int columnCount

The count of the columns.

Returns
Type Description
object[,]

An array for the data.

ImportData(Stream, string)

Import all the data of the specified source of the file.

Declaration
public static object[,] ImportData(Stream fileStream, string sourceName)
Public Shared Function ImportData(fileStream As Stream, sourceName As String) As Object(,)
Parameters
Type Name Description
Stream fileStream

The fileStream of a workbook.

string sourceName

The name of the data source. The source name could be:
worksheet "Sheet1"
table "Sheet1!Table1"
range "Sheet1!A1:C5"

Returns
Type Description
object[,]

An array for the data.

ImportData(Stream, string, int, int, int, int)

Imports data from a specified range in a workbook stream.

This method reads the range identified by worksheetName, row, column, rowCount, and columnCount from the workbook data in fileStream.

If the imported range contains a single cell value, the result is still returned as a two-dimensional array with one row and one column.

Declaration
public static object[,] ImportData(Stream fileStream, string worksheetName, int row, int column, int rowCount, int columnCount)
Public Shared Function ImportData(fileStream As Stream, worksheetName As String, row As Integer, column As Integer, rowCount As Integer, columnCount As Integer) As Object(,)
Parameters
Type Name Description
Stream fileStream

The input stream that contains workbook data. Must not be null.

string worksheetName

The name of the worksheet that contains the range to import.

int row

The zero-based row index of the first row in the range.

int column

The zero-based column index of the first column in the range.

int rowCount

The number of rows to import.

int columnCount

The number of columns to import.

Returns
Type Description
object[,]

A two-dimensional array that contains the imported range data.

Examples
worksheet.Range["A1:B3"].Value = new object[,] {
    {"Name", "Value"},
    {"Test", 100},
    {"Hello", 200}
};
MemoryStream outputStream = new MemoryStream();
workbook.Save(outputStream, SaveFileFormat.Xlsx);
object[,] data = Workbook.ImportData(
    new MemoryStream(outputStream.ToArray()), "Sheet1", 0, 0, 3, 2);
Exceptions
Type Condition
ArgumentException

Thrown when the specified worksheet does not exist.