建站代码网

热门标签

创建表单输入的EXCEL

ASP表单输入可以转化为你能想到的几乎任何类型的格式,一般来说,大多数表单输入要么被传递到数据库,如Access或SQL服务器,要么输出被发送到电子邮件地址或一些其他应用程序。在前面的例子中,我们已经演示了ASP表单输入是怎样被用来直接写一个永久的html文件到服务器的。 ASP表单输入到HTML。在这个例子中,我们将采取用户输入,并在服务器上创建了输入一个Excel文件。用户输入的这个标题将被用来命名该文件,所以标题包含!@#$%^&*()+=是无效的。当您的网站上在使用此脚本时,请记住,您执行的.asp代码的目录必须在服务器上建立的用户写出权限。

<% 'Check to see if title has been entered or not 测试标题是否输入或者输出 u_title=request.form("u_title") if u_title = "" then %> <html> <body bgcolor="#FFFFFF"> <!-- Input form area - This will only display when no Title has been entered --> <form method="POST" action="<%= request.servervariables("script_name") %>"> document Title<br> <input type="text" name="u_title" size="35"> <br><br> Cell 1 <br> <textarea rows="2" name="u_cell1" cols="35"></textarea> <br><br> Cell 2 <br> <textarea rows="2" name="u_cell2" cols="35"></textarea> <input type="submit" value="Submit" ></p> </form> <% else ' If there is a user inputted title 如果用户输入标题 ' get all of the user inputed values 获取用户的输入值 u_title=request.form("u_title") u_cell1=request.form("u_cell1") u_cell2=request.form("u_cell2") ' Varible created fo excel file name. Spaces are changed to underscores 创建Excel文件名的变量. 空间更改为下划线 ' and later the current date is added in attempts to create a unique file 之后当前的日期将会添加到创建到特定的文件 ' Users are not prevented from entering characters [email protected]#$%^&*()+= that are 用户是不会阻止字符输出的 ' invlaid file names in this example 这个例子的无效的文件名 g_filename=replace(u_title," ","_") set fso = createobject("scripting.filesystemobject") ' create the text (xls) file to the server adding the -mmddyyyy after the g_title value 创建文本(xls)文件到服务器加上 Set act = fso.CreateTextFile(server.mappath(""&g_filename & "-"& month(date())& day(date())& year(date()) &".xls"), true) ' write all of the user input to the text (xls) document 写入用户的输出到文本(xls)文件 ' The .xls extension can just as easily be .asp or .inc whatever best suits your needs xls扩展名文件 会容易的变为不管什么都适合你的需求的.asp或者是.inc ' Providing that you remove the info contained in the header and remove the xml 提供你移动表头包含的信息和移动XML。 ' reference in the html tag that starts the page/excel file. It is to add gridlines and 启动页面/excel文件的html标签的参考 ' a title to the excel worksheet excel 工作表的标题 act.WriteLine "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">" act.WriteLine "<head>" act.WriteLine "<!--[if gte mso 9]><xml>" act.WriteLine "<x:ExcelWorkbook>" act.WriteLine "<x:ExcelWorksheets>" act.WriteLine "<x:ExcelWorksheet>" act.WriteLine "<x:Name>"& u_title &"</x:Name>" act.WriteLine "<x:WorksheetOptions>" act.WriteLine "<x:Print>" act.WriteLine "<x:ValidPrinterInfo/>" act.WriteLine "</x:Print>" act.WriteLine "</x:WorksheetOptions>" act.WriteLine "</x:ExcelWorksheet>" act.WriteLine "</x:ExcelWorksheets>" act.WriteLine "</x:ExcelWorkbook>" act.WriteLine "</xml>" act.WriteLine "<![endif]--> " act.WriteLine "</head>" act.WriteLine "<body>" act.WriteLine "<table>" act.WriteLine "<tr>" act.WriteLine "<td>" act.WriteLine u_cell1 act.WriteLine "</td>" act.WriteLine "<td>" act.WriteLine u_cell2 act.WriteLine "</td>" act.WriteLine "</tr>" act.WriteLine "</table>" act.WriteLine "</body>" act.WriteLine "</html>" ' close the document 关闭这个文件 act.close %> Your excel has been successfully create and can be viewed by clicking 你的excel 已经成功创建,可以通过点击来查看到 <a href="<%= g_filename &"-"& month(date())& day(date())& year(date()) %>.xls" target="_blank">here</a> <% ' end check of form input 最后测试表单输出 end if %> </body> </html>


X