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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Write to an already opened excel file (through openfiledialog)

Thread ID:





142033 Jan 15,2019 08:56 AM UTC Jan 16,2019 12:23 PM UTC ASP.NET Web Forms 1
Tags: XlsIO
Christian Ademius
Asked On January 15, 2019 12:18 PM UTC

Hello SyncFusion. 

I am new to C#.NET development and I am trying to figure out how to write data into specific sheets and cells in an workbook. This workbook does not have a specific path, instead it is opened by another method and I´d like to write data to it by another method (seperate button on the winform menu).

Is there a way to do this? 
Alternatively a method during the same event click writes to the excel file once it opens. Not sure what approach is best here.

This is the code. 

private void selectHeatBalanceToolStripMenuItem_Click(object sender, EventArgs e)
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter = "xls files (*.xls)|*.xls|xlsx files (*.xlsx)|*.xlsx";
                openFileDialog.FilterIndex = 2;
                openFileDialog.RestoreDirectory = true;
                Workbook wbook;
                Worksheet wsheet;
                _Application excel = new _Excel.Application();
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                    excel = new _Excel.Application();
                    wbook = excel.Workbooks.Open(openFileDialog.FileName);
                    excel.Visible = true;

Mohan Chandran [Syncfusion]
Replied On January 16, 2019 12:23 PM UTC

Hi Christian, 

Thank you for contacting Syncfusion support. 

We have shared a sample to open a Excel file using open File dialog and to manipulate it. This can be downloaded from the following link. The code that helps to achieve this requirement is shared below. 

Code snippet: 
ExcelEngine excelEngine = new ExcelEngine(); 
IApplication application = excelEngine.Excel; 
//The workbook is opened. 
IWorkbook workbook = null; 
OpenFileDialog openFileDialog = new OpenFileDialog(); 
openFileDialog.InitialDirectory = "c:\\"; 
openFileDialog.Filter = "xls files (*.xls)|*.xls|xlsx files (*.xlsx)|*.xlsx"; 
openFileDialog.FilterIndex = 2; 
openFileDialog.RestoreDirectory = true; 
if (openFileDialog.ShowDialog() == DialogResult.OK) 
    workbook = application.Workbooks.Open(openFileDialog.FileName, ExcelOpenType.Automatic); 
//The first worksheet object in the worksheets collection is accessed. 
IWorksheet worksheet = workbook.Worksheets[0]; 

Please refer the UG documentation from the following link to know about worksheet manipulation in XlsIO. 

Kindly try this and let us know whether it helps. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon