Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to make calculation based on the quantity that user key in with the data(column) in the excel file that we link in c# ?

What I have tried:

C#
using Excel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace myproject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DataSet result;

        private void btnopen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Excel Workbook|*.xlsx", ValidateNames = true })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);
                    IExcelDataReader reader = ExcelReaderFactory.CreateOpenXmlReader(fs);
                    reader.IsFirstRowAsColumnNames = true;
                    result = reader.AsDataSet();
                    Sheetname.Items.Clear();
                    foreach (DataTable dt in result.Tables)
                        Sheetname.Items.Add(dt.TableName);
                    reader.Close();
                }
            }
        }

        private void Sheetname_SelectedIndexChanged(object sender, EventArgs e)
        {
            dataview.DataSource = result.Tables[Sheetname.SelectedIndex];
        }
    }
}
Posted
Updated 13-Jul-17 5:11am
v3
Comments
Maciej Los 13-Jul-17 2:37am    
"please show me the full coding" - this is not a question at all!
You have to provide at least a minimum of information about your issue.
Member 13305578 13-Jul-17 4:22am    
i've update the coding. i'm not yet do the coding about the calculation b'cuz i don't know how to do it ! lol
Maciej Los 13-Jul-17 11:32am    
First of all - i appreciate that you improved a question, but unfortunately it's not enough. You didn't explained what you want to calculate. ;(
Member 13305578 31-Jul-17 4:21am    
i want to calculate number in column B, D, and F in excel file times user input from the textbox. the flow is like this : after i debug the project, i will open the file from the button click. after the file is display, i want calculate the number in column B, D, F from the excel file that have been import times user input from the textbox. is it clear? :)
ZurdoDev 13-Jul-17 11:19am    
Where are you stuck?

1 solution

 
Share this answer
 

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