void Button2_Click(object sender, EventArgs e) { NpoiLib npl = new NpoiLib(); List<Row> list = npl.ReadExcel(Server.MapPath("text.xls"), 0); Response.Write("<table><tr><td>111</td><td>222</td><td>333</td></tr>"); int i = 0; string[] explicitListValues = new string[] { "AS", "CE CP", "SC IC", "Others" }; foreach (Row r in list) { if (r != null) { Cell c = r.GetCell(0); NPOI.SS.Util.CellRangeAddressList ranglist = new NPOI.SS.Util.CellRangeAddressList(); ranglist.AddCellRangeAddress(new CellRangeAddress(0, 10, 0, 3)); DVConstraint dvconstraint = DVConstraint.CreateExplicitListConstraint(explicitListValues); HSSFDataValidation dataValidation = new HSSFDataValidation(ranglist, dvconstraint); ((HSSFSheet)c.Sheet).AddValidationData(dataValidation); string v1 = npl.ReadRowData(r, 0); string v2 = npl.ReadRowData(r, 1); string v3 = npl.ReadRowData(r, 2); Response.Write("<tr><td>" + v1 + "</td><td>" + v2 + "</td><td>" + v3 + "</td></tr>"); } } Response.Write("</table>"); }
void Button3_Click(object sender, EventArgs e) { NpoiLib npl = new NpoiLib(); List<Row> list = npl.ReadExcel(Server.MapPath("text.xls"), 0); string[] data = new string[] { "AS", "CE CP", "SC IC", "Others" }; foreach (Row r in list) { npl.WriteDropDownList2(r.Sheet, 0, 0, 2, 3, data); } npl.SaveExcel(Server.MapPath("text2.xls")); Response.Write("<script>alert('CreatSuc!');</script>"); }