Approved
Last Updated: 22 Nov 2019 11:13 by ADMIN
ADMIN
Deyan
Created on: 25 Apr 2016 17:37
Category: SpreadProcessing
Type: Feature Request
12
SpreadProcessing: Introduce conversion from DataTable to RadWorkbook/RadWorksheet and vice versa
Expose an easy way to create .xlsx documents from DataTable objects.
4 comments
ADMIN
Nikolay Demirev
Posted on: 22 Nov 2019 11:13

Hi Doug,

Thank you for your feedback. We are tracking the interest for this feature, but still, it is not in our immediate plans for implementing.

While waiting for it you could use this sample code in order to create a Workbook from a DataSet:

private Workbook ImportDataSetToWorkbook(DataSet dataSet)
{
	for (int i = 0; i < dataSet.Tables.Count; i++)
	{
		workbook.Worksheets.Add();

		DataTable currentTable = dataSet.Tables[i];
		Worksheet currentWorksheet = workbook.Worksheets[i];

		currentWorksheet.Name = currentTable.TableName;

		ImportDataFromDataSetToWorksheet(currentTable, currentWorksheet);
	}
}

private void ImportDataFromDataSetToWorksheet(DataTable table, Worksheet worksheet)
{
	for (int col = 0; col < table.Columns.Count; col++)
	{
		CellSelection cell = worksheet.Cells[0, col];
		cell.SetValue(table.Columns[col].ToString());
	}

	for (int row = 0; row < table.Rows.Count; row++)
	{
		var currentRow = table.Rows[row];

		for (int col = 0; col < table.Columns.Count; col++)
		{
			CellSelection cell = worksheet.Cells[row + 1, col];
			var currentCellValue = currentRow.ItemArray[col];

			if (currentCellValue.GetType() == typeof(double) || currentCellValue.GetType() == typeof(int))
			{
				cell.SetValue((double)currentCellValue);
			}
			else if (currentCellValue.GetType() == typeof(DateTime))
			{
				cell.SetValue((DateTime)currentCellValue);
			}
			else if (currentCellValue.GetType() == typeof(bool))
			{
				cell.SetValue((bool)currentCellValue);
			}
			else
			{
				cell.SetValue(currentCellValue.ToString());
			}
		}
	}
}

Regards,
Nikolay Demirev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Doug
Posted on: 17 Nov 2019 01:31
I agree completely.  Hope this feature is added soon.  We also use SyncFusion at my company.  SyncFusion has an ImportDataTable that makes it much easier than what Progress Telerik currently has.  You are falling behind your competition.
ADMIN
Tanya
Posted on: 27 Sep 2018 15:53
Hi,

Thank you for sharing your feedback. Please, make sure to cast your vote for this implementation and continue following the item so you can receive updates about status changes on it.

Until this task gets implemented, you can add the data from the DataTable by iterating the records and adding them using the SetValue() method of the CellSelection class. More information about this method is available at https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/working-with-cells/get-set-clear-properties#value-property .

Regards,
Tanya
TRANSEPT
Posted on: 25 Sep 2018 11:01
Hi Team , 
Hope you will start very soon developing this part , it's really important such feature ,

Thanks for your efforts