Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用NPOI导出到excel 2003,其中一列为印度数字格式_C#_Asp.net_Excel - Fatal编程技术网

C# 使用NPOI导出到excel 2003,其中一列为印度数字格式

C# 使用NPOI导出到excel 2003,其中一列为印度数字格式,c#,asp.net,excel,C#,Asp.net,Excel,我正在使用VS2008、ASP.net、C#net、NPOI 1.2.3 dll 我有一个web应用程序,它使用NPOI dll导出到Excel2003。如何使用程序在导出的excel表格中以印度样式(12,12,34567.89)显示带千位分隔符的数字?内置公式sum()应用于这些数字格式的导出单元格 提前谢谢 代码如下所述 受保护的无效btnGenerateReport\u单击(对象发送方,事件参数e) { //获取要报告的数据 //var userAccounts=Membership.G

我正在使用VS2008、ASP.net、C#net、NPOI 1.2.3 dll

我有一个web应用程序,它使用NPOI dll导出到Excel2003。如何使用程序在导出的excel表格中以印度样式(12,12,34567.89)显示带千位分隔符的数字?内置公式sum()应用于这些数字格式的导出单元格

提前谢谢

代码如下所述

受保护的无效btnGenerateReport\u单击(对象发送方,事件参数e) { //获取要报告的数据 //var userAccounts=Membership.GetAllUsers()

//创建新工作簿和名为“用户帐户”的工作表
HSSFWorkbook=新的HSSFWorkbook();
Sheet Sheet=workbook.CreateSheet(“用户帐户”);
//var sheet=workbook.CreateSheet(“用户帐户”);
//添加标题标签
int rowIndex=0;
行=sheet.CreateRow(行索引);
row.CreateCell(0.SetCellValue(“用户名”);
row.CreateCell(1.SetCellValue(“电子邮件”);
row.CreateCell(2).SetCellValue(“连接”);
row.CreateCell(3.SetCellValue(“上次登录”);
行.CreateCell(4).SetCellValue(“已批准?”);
行.CreateCell(5).SetCellValue(“数量”);
rowIndex++;
//数字格式开始
CellStyle detailCurrencySubtotalCellStyle=workbook.CreateCellStyle();
detailCurrencySubtotalCellStyle.BorderTop=CellBorderType.THIN;
detailCurrencySubtotalCellStyle.BorderBottom=CellBorderType.THIN;
Font detailCurrencySubtotalFont=工作簿.CreateFont();
detailCurrencySubtotalFont.Boldweight=(短)FontBoldWeight.BOLD;
detailCurrencySubtotalCellStyle.SetFont(detailCurrencySubtotalFont);
detailCurrencySubtotalCellStyle.DataFormat=HSSFDataFormat.GetBuiltInformation(“##,##,##,##,##0.00”);
//数字格式结束
行=sheet.CreateRow(行索引);
row.CreateCell(0.SetCellValue(“preejo”);
row.CreateCell(1).SetCellValue(“preejo@gmail.com");
第行CreateCell(2).SetCellValue(“2014年1月1日”);
第行CreateCell(3).SetCellValue(“2014年1月27日”);
row.CreateCell(4).SetCellValue(“true”);
//row.CreateCell(5).SetCellValue((121234567.89).ToString(“N”,新文化信息(“hi-IN”)));
//CreateCell(5).SetCellValue(Convert.ToDouble(123456.78));
row.CreateCell(5).SetCellValue(123456.78);
//row.GetCell(5).CellStyle=CellStyle;
row.GetCell(5.CellStyle=detailCurrencySubtotalCellStyle;
rowIndex++;
行=sheet.CreateRow(行索引);
row.CreateCell(0.SetCellValue(“joby”);
row.CreateCell(1).SetCellValue(“joby@gmail.com");
第行CreateCell(2).SetCellValue(“2013年1月1日”);
第3行CreateCell.SetCellValue(“2013年1月27日”);
row.CreateCell(4).SetCellValue(“false”);
CreateCell(5).SetCellValue(Convert.ToDouble(2323313.43));
//row.GetCell(5).CellStyle=CellStyle;
row.GetCell(5.CellStyle=detailCurrencySubtotalCellStyle;
//}
//自动调整每列的大小
for(int i=0;i
试试看
String.Format(“{0:#,###0}”,您的号码为双精度)

导入文档后,是否会将数字作为字符串插入,从而破坏某些Excels功能?
        // Create a new workbook and a sheet named "User Accounts"
        HSSFWorkbook workbook = new HSSFWorkbook();
        Sheet sheet = workbook.CreateSheet("User Accounts");
        //var sheet = workbook.CreateSheet("User Accounts");

        // Add header labels
        int rowIndex = 0;
        Row row = sheet.CreateRow(rowIndex);
        row.CreateCell(0).SetCellValue("Username");
        row.CreateCell(1).SetCellValue("Email");
        row.CreateCell(2).SetCellValue("Joined");
        row.CreateCell(3).SetCellValue("Last Login");
        row.CreateCell(4).SetCellValue("Approved?");
        row.CreateCell(5).SetCellValue("Qty");
        rowIndex++;



        //NUMBER FORMAT BEGIN
        CellStyle detailCurrencySubtotalCellStyle = workbook.CreateCellStyle();
        detailCurrencySubtotalCellStyle.BorderTop = CellBorderType.THIN;
        detailCurrencySubtotalCellStyle.BorderBottom = CellBorderType.THIN;
        Font detailCurrencySubtotalFont = workbook.CreateFont();
        detailCurrencySubtotalFont.Boldweight = (short)FontBoldWeight.BOLD;
        detailCurrencySubtotalCellStyle.SetFont(detailCurrencySubtotalFont);
    detailCurrencySubtotalCellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("##,##,##,##0.00");

        //NUMBER FORMAT END

        row = sheet.CreateRow(rowIndex);
        row.CreateCell(0).SetCellValue("preejo");
        row.CreateCell(1).SetCellValue("preejo@gmail.com");
        row.CreateCell(2).SetCellValue("01/Jan/2014");
        row.CreateCell(3).SetCellValue("27/Jan/2014");
        row.CreateCell(4).SetCellValue("true");
        //row.CreateCell(5).SetCellValue(((121234567.89).ToString("N", new CultureInfo("hi-IN"))));
        //row.CreateCell(5).SetCellValue(Convert.ToDouble(123456.78));
        row.CreateCell(5).SetCellValue(123456.78);
        //row.GetCell(5).CellStyle = cellStyle;
        row.GetCell(5).CellStyle = detailCurrencySubtotalCellStyle;




        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        row.CreateCell(0).SetCellValue("joby");
        row.CreateCell(1).SetCellValue("joby@gmail.com");
        row.CreateCell(2).SetCellValue("01/Jan/2013");
        row.CreateCell(3).SetCellValue("27/Jan/2013");
        row.CreateCell(4).SetCellValue("false");
        row.CreateCell(5).SetCellValue(Convert.ToDouble(2323313.43));
        //row.GetCell(5).CellStyle = cellStyle;
        row.GetCell(5).CellStyle = detailCurrencySubtotalCellStyle;

        //}



        // Auto-size each column
        for (int i = 0; i < sheet.GetRow(0).LastCellNum; i++)
            sheet.AutoSizeColumn(i);


        // Add row indicating date/time report was generated...
        sheet.CreateRow(rowIndex + 1).CreateCell(0).SetCellValue("Report generated on " + DateTime.Now.ToString());

        //formula
        rowIndex++;
        row = sheet.CreateRow(rowIndex);
        Cell cell = row.CreateCell(5);

        cell.SetCellType(CellType.FORMULA);
        cell.CellFormula = string.Format("SUM(F{0}:F{1})", 2, 3);


        cell.CellStyle = detailCurrencySubtotalCellStyle;



        // Save the Excel spreadsheet to a MemoryStream and return it to the client
        using (MemoryStream exportData = new MemoryStream())
        {
            workbook.Write(exportData);

            string saveAsFileName = string.Format("MembershipExport-{0:d}.xls", DateTime.Now).Replace("/", "-");

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", saveAsFileName));
            Response.Clear();
            Response.BinaryWrite(exportData.GetBuffer());
            Response.End();
        }
    }