向前端插入值 [英] inserting values to frontend

查看:73
本文介绍了向前端插入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已使用列表将数据从数据表导出到excel.我已将值插入列表,并将其传递到网格中,并使用ExporttoExcel()将其导出到excel.
这是列表的代码...

Hi,
I have exported values from datatable to excel using list.. I have inserted values to the list and passed that in a grid and using ExporttoExcel() i have exported it to excel..
here is the code for list...

protected void Page_Load(object sender, EventArgs e)
        {
            List<student> Students = new List<student>(){
                new Student() { Name = "Jack", Age = 15, StudentId = 100 },
                new Student() { Name = "Smith", Age = 15, StudentId =101 },           
                new Student() { Name = "Smit", Age = 15, StudentId = 102 },
                new Student() { Name = "Anusha", Age = 23, StudentId = 104 }
            };
            ListtoDataTableConverter converter = new ListtoDataTableConverter();
            dt = converter.ToDataTable(Students);
            GridView_Result.DataSource = Students;
            GridView_Result.DataBind();
        }


现在,我想从前端插入值,并希望将其保存在excel中.而不是使用网格,我将使用文本字段,输入值后,如果您单击插入"按钮,则应将其保存在excel表中...有没有办法...

感谢一吨.. !!


now, i want to insert values from front end and i want that to be saved in excel.. instead of using grid, i will use a text field and after entering value and if u click insert button, it should be saved in excel sheet...is there any ways to do so ...

thanks a ton..!!

推荐答案

检查此代码

check this code

//namespace for excel
using excel = Microsoft.Office.Interop.Excel;



	    excel.Application eApp = new excel.Application();
            excel.Worksheet eWs = new excel.Worksheet();
            excel.Workbook eWs1;
            eWs1 = (excel.Workbook)(eApp.Workbooks.Add([Excel Path]));
            eWs = (excel.Worksheet)eWs1.Worksheets[0];
            eApp.Visible = true;

	    DataTable dt = new DataTable();

            //fill data table here
            //make current sheet active

            eWs.Select(Type.Missing);

		int iRow = 1;
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    
                    
                    eWs.Cells[iRow, 1] = Convert.ToString(dr["column1"]);
                    eWs.Cells[iRow, 2] = Convert.ToString(dr["column2"]);
                    eWs.Cells[iRow, 3] = Convert.ToString(dr["column3"]);
                    eWs.Cells[iRow, 4] = Convert.ToString(dr["column4"]);
                     iRow++;
                 }
             }
//save the workbook

eWs1.SaveAs([Excel Path], Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);


这篇关于向前端插入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆