Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I want to Read an excel file using C# but

1. I dont want to use Interop since microsoft itself advises not to use that bcoz of various problems
2. I dont want to use OpenXML also since my file will be password protected, which will not be supported by OpenXML


Please suggest any other Idea other than this.
Posted

Hi I'm using NPOI project in order to process excel files
 
Share this answer
 
Comments
Mathi2code 4-Sep-13 9:25am    
Hi, Thanks for reply.
Will NPOI supports password protected file and .xlsb file ?
Nissim Salomon 4-Sep-13 9:46am    
I didn't try it but i think it does basically its a tool that exist in the market for quiet a lot. the first version was for a java framework and imported into .net
Mathi2code 10-Oct-13 22:47pm    
Hi, You can use krypto tool to decrypt the password protected file but .xlsb is not supported by NPOI I could read .xlsm file. Thanks
Hi Mathi, try this;

C#
IExcelDataReader iExcelDataReader = null;
 
            FileStream oStream = File.Open(filepath, FileMode.Open, FileAccess.Read);
 
            iExcelDataReader = ExcelReaderFactory.CreateOpenXmlReader(oStream);
 
            iExcelDataReader.IsFirstRowAsColumnNames = true;
 
            DataSet dsUnUpdated = new DataSet();
 
            dsUnUpdated = iExcelDataReader.AsDataSet();
 
            iExcelDataReader.Close();
 
            if (dsUnUpdated == null)
            {
                oStream = File.Open(filepath, FileMode.Open, FileAccess.Read);
                iExcelDataReader = ExcelReaderFactory.CreateBinaryReader(oStream);
 
                iExcelDataReader.IsFirstRowAsColumnNames = true;
 
                dsUnUpdated = iExcelDataReader.AsDataSet();
 
                iExcelDataReader.Close();
            }


you need to add Namespace for this;

C#
using System.Runtime.Serialization.Formatters.Binary;


I hope this will help you.

Thank's

Mohan G
 
Share this answer
 
v2
Comments
Mathi2code 4-Sep-13 9:28am    
I'm not getting this IExcelDataReader.
Could you please help me to refer this interface.
What namespace do I need to get this interface.

Also will this support .xlsb and .xlsm type files.
Kindly help.
Mohan Gopi 4-Sep-13 9:39am    
you need to add namespace

Using Excel;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900