但遇到一些security的問題,底下為當初提供給他的解決方法
步驟一
在本機建立一個分享資料夾,將檔案移入
步驟二
在[開始]執行 \\hostname\sharefoldername *hostname指的是本機電腦名稱,
步驟三
在步驟二執行後彈跳出來的視窗找尋要執行的html檔,
這個步驟的目的在建立一個link為\\hostname\
步驟四
建立信任網站格式
using System;
using System.Web;
using System.IO;
using NPOI;
using NPOI.HSSF;
using NPOI.HSSF.Util;
using NPOI.HSSF.Model;
using NPOI.HSSF.UserModel;
public class filedownload : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
MemoryStream ms = new MemoryStream();
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.CreateSheet("sample");
HSSFCell cell = null;
HSSFCellStyle borderStyle = null;
HSSFCellStyle colorStyle = null;
HSSFCellStyle fontStyle = null;
HSSFCellStyle heightStyle = null;
HSSFCellStyle spanStyle = null;
HSSFCellStyle wrapStyle = null;
HSSFFont font = null;
borderStyle = workbook.CreateCellStyle();
colorStyle = workbook.CreateCellStyle();
fontStyle = workbook.CreateCellStyle();
heightStyle = workbook.CreateCellStyle();
spanStyle = workbook.CreateCellStyle();
wrapStyle = workbook.CreateCellStyle();
//Style設定
borderStyle.BorderTop = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderLeft = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderBottom = HSSFCellStyle.BORDER_THIN;
borderStyle.BorderRight = HSSFCellStyle.BORDER_THIN;
colorStyle.FillForegroundColor = HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
colorStyle.FillPattern = HSSFCellStyle.SOLID_FOREGROUND;
fontStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
fontStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
heightStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
heightStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
spanStyle.Alignment = HSSFCellStyle.ALIGN_CENTER;
spanStyle.VerticalAlignment = HSSFCellStyle.VERTICAL_CENTER;
wrapStyle.WrapText = true;
//指定紙張大小 A3=8, A4=9, Letter=1
sheet.PrintSetup.PaperSize = 9;
//指定直式或橫式 true=橫式 false=直式
sheet.PrintSetup.Landscape = true;
//藏隱格線
sheet.DisplayGridlines = false;
//設定欄寬
sheet.SetColumnWidth(0, 24 * 256);
sheet.SetColumnWidth(1, 24 * 256);
//指定列高
cell = sheet.CreateRow(0).CreateCell(0);
cell.SetCellValue("指定列高");
cell.CellStyle = heightStyle;
sheet.GetRow(0).HeightInPoints = 50;
//字型大小
font = workbook.CreateFont();
font.FontHeightInPoints = 14;
font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;
fontStyle.SetFont(font);
cell = sheet.CreateRow(1).CreateCell(0);
cell.CellStyle = fontStyle;
cell.SetCellValue("字型大小14粗體");
//合併儲存格
cell = sheet.CreateRow(2).CreateCell(0);
cell.SetCellValue("合併儲存格");
cell.CellStyle = spanStyle;
sheet.AddMergedRegion(new Region(2, 0, 3, 1));
//Wrap
cell = sheet.CreateRow(4).CreateCell(0);
cell.SetCellValue(string.Format("換行{0}測試", System.Environment.NewLine));
cell.CellStyle = wrapStyle;
//增加邊框
cell = sheet.CreateRow(5).CreateCell(1);
cell.SetCellValue("邊框 ");
cell.CellStyle = borderStyle;
//背景
cell = sheet.CreateRow(6).CreateCell(0);
cell.SetCellValue("背景");
cell.CellStyle = colorStyle;
//插入分頁
sheet.SetRowBreak(cell.RowIndex);
//下一頁資料
cell = sheet.CreateRow(7).CreateCell(0);
cell.SetCellValue("下一頁資料");
workbook.Write(ms);
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.AddHeader("Content-Disposition", "attachment; filename=myExcel.xls");
context.Response.BinaryWrite(ms.ToArray());
}
public bool IsReusable
{
get
{
return false;
}
}
}