将TextBox数据写入MS Excel文档 [英] Writing TextBox data to MS Excel document

查看:96
本文介绍了将TextBox数据写入MS Excel文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对asp.net c#有疑问。我正在开发一个Web项目,其中有一个Web表单,其中包含许多文本框条目和一个提交按钮。



输入数据后文本框和单击提交按钮,应从文本框中读取所有数据并将其插入以表单形式设计的Excel文档中。 Excel文档有texbox,需要从asp.net webform填充。这怎么可能?



我有一个概念: - 我会将Excel表格的副本上传到网站上。当用户填写表单并单击提交时,将调用Excel文档的实例,并插入数据。之后,Excel工作表实例将重命名为username。并保存在某个地方。是否可以创建这样的Excel工作表实例?

I have a doubt related to asp.net c#. I am developing a web project, in which, there is a web form, that has a number of textbox entries and a submit button.

After entering the data in the textboxes and clicking submit button, all the data should be read from the Textboxes and inserted in to an Excel document designed in the form of a "form". The Excel document has texboxes, which need to be populated from the asp.net webform. How is this possible ?

I have a concept in mind :- I will upload a copy of the Excel sheet into the website. When a user fills the form and click on submit, an instance of the Excel document is called, and data is inserted. After that, the Excel sheet instance is renamed as "username" and saved somewhere. Is it possible to create instances of Excel sheets like this ?

推荐答案

很抱歉没有这样做。

我可以创建一个新的空白实例excel电子表格,但我不知道如何打开现有文件,创建该文件的副本,插入数据并以新名称保存。



我用来将数据写入空白文件的代码是: -



Sorry for not doing that.
I could create a new blank instance of the excel spreadsheet, but I don't know how to open an existing file, create a duplicate of that file, insert data and save it in a new name.

The code that I used to write data to a blank file is :-

protected void btnSubmission_Click(object sender, EventArgs e)
{
    Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
    Workbook wb = xlapp.Workbooks.Add(XlSheetType.xlWorksheet);
    Worksheet ws = (Worksheet)xlapp.ActiveSheet;

    xlapp.Visible = true;

    String s1 = TextBox2.Text;
    ws.Cells[4,4]=s1;
}


这篇关于将TextBox数据写入MS Excel文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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