This is a migrated thread and some comments may be shown as answers.

Import stream from Database

5 Answers 241 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
G
Top achievements
Rank 1
G asked on 27 Feb 2013, 04:35 PM
Hi,

I'm wondering if there is a simple way to import a stream (Excel file) from a database instead of the usual case of study which open a dialog box?

=> XlsxFormatProvider().Import(stream)

Is it necessary to override ImportOverride in XlsxFormatProvider in order to not generate error like "no directory found!" (avoid those kind of control)

Do you have a simple solution to perform that?
Thanks

JG



5 Answers, 1 is accepted

Sort by
0
Andrew
Telerik team
answered on 28 Feb 2013, 08:59 AM
Hello GJ,

Overriding ImportOverride in XlsxFormatProvider is not necessary. There is a static class called WorkbookFormatProvidersManager which has a method Import. Using this method you can retrieve a Workbook object and set it to your RadSpreadsheet. Here is some code you can find useful:

using (FileStream fileStream = File.OpenRead("test.xlsx"))
{
this.spreadsheet.Workbook = WorkbookFormatProvidersManager.Import(".xlsx", fileStream);
}
NOTE: In order to use our XlsxFormatProvider you need to register it first using the following code:
WorkbookFormatProvidersManager.RegisterFormatProvider(new XlsxFormatProvider());

Hope that helps. If you have any other difficulties get back to us.

 All the best,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
G
Top achievements
Rank 1
answered on 28 Feb 2013, 03:29 PM
Hi!

Thanks this works perfectly.

Is it possible to import other excel file format such as .xls/.xlsm ?

GJ
0
Andrew
Telerik team
answered on 01 Mar 2013, 01:42 PM
Hi GJ,

For the time being RadSpreadsheet supports three formats as you can read here. For Q2 2013 we plan to extend our XLSX support, but unfortunately new formats beside those described in this article won't be supported. However after Q2 release we will evaluate the effort and demand of new formats and if possible add support for the most requested ones.

Regards,
Andrew
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mr
Top achievements
Rank 1
answered on 20 Feb 2014, 05:48 AM
Hello
 follwing code i am using
  Workbook workbook;
                IWorkbookFormatProvider formatProvider = new XlsxFormatProvider();
                using (FileStream input = new FileStream(filePath, FileMode.Open))
                {
                    workbook = formatProvider.Import(input);
                }
   when i am trying to import the differnt excel files then some files successfully loaded and some are not giving the follwoing two kind of errors
Error 1:
{System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Types.Ref..ctor(String range) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Types\Ref.cs:line 51
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Types.StringConvertibleFactory.<.cctor>b__1(String s) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Types\StringConvertibleFactory.cs:line 23
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Types.StringConvertibleFactory.CreateInstance(Type type, String value) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Types\StringConvertibleFactory.cs:line 45
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlAttribute`1.SetStringValue(String value) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlAttributeOfT.cs:line 88
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlElementBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlElementBase.cs:line 140
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlElementBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlElementBase.cs:line 159
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlElementBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlElementBase.cs:line 159
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlElementBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlElementBase.cs:line 159
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlElementBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlElementBase.cs:line 159
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.OpenXml.OpenXmlPartBase.ReadFrom(IOpenXmlReader reader) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\OpenXml\OpenXmlPartBase.cs:line 63
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Import.XlsxImporter.ReadXlsxPartFromPackage(ZipPackageEntry zipPackageEntry, XlsxPartBase part) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Import\XlsxImporter.cs:line 120
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Import.XlsxImporter.ReadAllParts(Dictionary`2 zipPackageEntries, ContentTypesPart contentTypesPart) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Import\XlsxImporter.cs:line 136
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Import.XlsxImporter.Import(Stream input, XlsxImportSettings settings) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Import\XlsxImporter.cs:line 99
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ImportOverride(Stream input) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\XlsxFormatProvider.cs:line 122
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.WorkbookFormatProviderBase.Import(Stream input) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\Core\FormatProviders\WorkbookFormatProviderBase.cs:line 39
   at DocumentViewer.MainWindow.LoadExcel(String filePath) in C:\Users\tufailm\Desktop\New folder\DocViewer\DocumentViewer\DocumentViewer\MainWindow.xaml.cs:line 135}
 
 
 
 
 
 
 
 
 
 
Error 2:
{System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Telerik.Windows.Documents.Spreadsheet.Core.DataStructures.QueueDictionary`2.get_Item(TKey key) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\Core\Core\DataStructures\QueueDictionary.cs:line 64
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Contexts.ResourceIndexedTable`1.get_Item(Int32 index) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Contexts\ResourceIndexedTable.cs:line 27
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Stylesheet.ColorElementBase.CreateThemableColor(XlsxWorkbookImportContext context) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Elements\Stylesheet\ColorElementBase.cs:line 127
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Stylesheet.FontElement.CopyPropertiesTo(XlsxWorkbookImportContext context, FontInfo font) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Elements\Stylesheet\FontElement.cs:line 233
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Stylesheet.FontsElement.CreateFontInfo(XlsxWorkbookImportContext context, FontElement fontElement) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Elements\Stylesheet\FontsElement.cs:line 84
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Stylesheet.FontsElement.CopyPropertiesTo(XlsxWorkbookImportContext context, ResourceIndexedTable`1 fontTable) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Elements\Stylesheet\FontsElement.cs:line 74
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Elements.Stylesheet.StyleSheetElement.CopyPropertiesTo(XlsxWorkbookImportContext context, StyleSheet styleSheet) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Elements\Stylesheet\StyleSheetElement.cs:line 202
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Model.Parts.StylesPart.Import(XlsxWorkbookImportContext context) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Model\Parts\StylesPart.cs:line 85
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.Import.XlsxImporter.Import(Stream input, XlsxImportSettings settings) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\Import\XlsxImporter.cs:line 106
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.OpenXml.Xlsx.XlsxFormatProvider.ImportOverride(Stream input) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\FormatProviders\OpenXml\Xlsx\XlsxFormatProvider.cs:line 122
   at Telerik.Windows.Documents.Spreadsheet.FormatProviders.WorkbookFormatProviderBase.Import(Stream input) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Documents\Spreadsheet\Core\FormatProviders\WorkbookFormatProviderBase.cs:line 39
   at DocumentViewer.MainWindow.LoadExcel(String filePath) in C:\Users\tufailm\Desktop\New folder\DocViewer\DocumentViewer\DocumentViewer\MainWindow.xaml.cs:line 135}
0
Boryana
Telerik team
answered on 21 Feb 2014, 02:49 PM
Hello,

Thank you for writing.

I kindly ask you to open a new support ticket and attach the xlsx files that cannot be imported there. Once we are able to replicate the issue on our side, we will do our best to address it. Thank you in advance.

I am looking forward to your reply.

Regards,
Boryana
Telerik
Tags
Spreadsheet
Asked by
G
Top achievements
Rank 1
Answers by
Andrew
Telerik team
G
Top achievements
Rank 1
Mr
Top achievements
Rank 1
Boryana
Telerik team
Share this question
or