We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to open and write to an existing excel file?

Hi, I'm a student learning Xamarin.Forms. I'd like to ask how do you open and write to an existing excel file? I read this article (https://help.syncfusion.com/file-formats/xlsio/loading-and-saving-workbook?cs-save-lang=1&cs-lang=csharp) but I get an error.    

//Creates a new instance for ExcelEngine.     
ExcelEngine excelEngine = new ExcelEngine();           
//Loads or open an existing workbook through Open method of IWorkbooks     
IWorkbook workbook = excelEngine.Excel.Workbooks.Open(@"filename.xlsx");

The error says "Argument 1: cannot convert from 'string' to 'System.IO.Stream'".
I know I should use a dependency but I'm not sure how to do it.
And from here (https://www.syncfusion.com/forums/120967/how-do-you-display-the-excel-sheet-on-your-phone), I copied this part:  
 
string resourcePath = "GettingStarted.xlsx";
Assembly assembly = typeof(App).GetTypeInfo().Assembly;
Stream fileStream = assembly.GetManifestResourceStream(resourcePath);
//Opens the workbook IWorkbook workbook = application.Workbooks.Open(fileStream);

But I get this error: An exception of type 'System.ArgumentNullException' occurred in Syncfusion.XlsIO.Portable.dll but was not handled in user code Additional information: Value cannot be null.

(Btw, I want to make an app that opens an existing excel file, write additional data (in different rows)to it every time the button is clicked.)

1 Reply

AV Abirami Varadharajan Syncfusion Team March 28, 2017 03:39 PM UTC

Hi Cathleen, 
  
Thank you for contacting Syncfusion support. 
  
We have prepared the sample to open and save the file in Xamarin platform. The sample can be downloaded from the following link. 
  
  
Note: We suspect issue might be occurred as if the file is not located in the provided location or else file shouldn’t have embedded in the resource. 
  
If you still able to reproduce the issue, then kindly modify and share the issue reproducing sample which will be helpful for us to provide prompt solution at the earliest. 
  
Regards, 
Abirami. 


Loader.
Up arrow icon