标签: npoi

NPOI像excel一样插入行

如何使用NPOI像excel一样插入一行?excel插入命令复制上一行的格式

谢谢!

npoi

5
推荐指数
2
解决办法
9504
查看次数

如何使用NPOI 2.0保存excel 2010+

我使用NPOI很长一段时间它总是有效但现在我需要使用.xlsx和至少Microsoft Office 2010.它可以工作,但当我尝试打开文件时它说它已损坏我无法修复它.这是我得到的错误:

Repaired Part: /xl/worksheets/sheet1.xml part with XML error.  Load error. Line 1, column 7550.
Repaired Records: Cell information from /xl/worksheets/sheet1.xml part
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

我有这个样本,我仍然遇到同样的问题:http://www.leniel.net/2014/02/npoi2.0-excel-2007-xssfworkbook-and-word-2007-xwpfdocument-support.html#sthash .T7qk6CSv.dpbs

c# excel corrupt xlsx npoi

5
推荐指数
1
解决办法
2600
查看次数

有没有办法使用 NPOI/C# 将 HTML 表格转换为 xls/xlsx 文件?

我的主要目标是在我的 .NET 应用程序中在服务器端动态创建一个包含 html 表的 xls。不过,我的 HTMLtable 的数据模型非常复杂,但我设法使用 dotliquid 为另一个用例创建了模型 - 导出到我的应用程序的 pdf 功能。在这里,我使用了基本对象中的 EO.pdf 库。

现在我希望不需要做一些“双重工作”,因为在我的代码的某个点,我有完整的 HTML 标记,PDF 实际是从中创建的。

生成我的pdf的代码:

#region plan

string legend = string.Empty;
string allg = string.Empty;
int lineCount = 0;
int dayCount = 0;

var plan = Utils.Pdf.ConvertToPdf.ConvertPlanTemplate(out allg, out legend, out lineCount, out dayCount);

if (RequestValues.Extension.ToLower() == "pdf")
{
    ...
    var doc = new EO.Pdf.PdfDocument();
    EO.Pdf.HtmlToPdf.ConvertHtml(plan, doc, options);
    ...
}
Run Code Online (Sandbox Code Playgroud)

在这里,我使用 EO 的“ConvertHtml”-Method 将我的 html(使用 dotliquid 创建)转换为我的 PdfDocument-Instance。长话短说,我正在 NPOI 中寻找这样的方法。有没有办法通过 NPOI 将 HTML 表格转换为 …

html c# xls apache-poi npoi

5
推荐指数
1
解决办法
4831
查看次数

在 C# 中使用 NPOI 将工作表从一个工作簿复制到另一个工作簿

我需要将一张工作表从一个工作簿复制到另一个工作簿。我正在尝试使用以下代码,但它不起作用:

ISheet newSheet = wb.GetSheetAt(0).CopySheet("WeeklyReport");
string filePath = "billing_template2.xlsx";
XSSFWorkbook billingWorkbook;
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
    billingWorkbook = new XSSFWorkbook(fs);
}

billingWorkbook.Add(newSheet);
Run Code Online (Sandbox Code Playgroud)

其中wb是源工作簿,billingWorkbook是我的目标工作簿。

注意:我的目标工作簿已经有一张工作表。我需要在这之后添加复制的工作表。

c# npoi

5
推荐指数
0
解决办法
3025
查看次数

返回excel文件而不将其保存在控制器内的服务器中

我想将 Excel 文件(使用 NPOI 库)返回给用户,而无需先将文件保存在服务器中。这是我的代码:

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Report(SalesReportViewModel model)
        {
            if (ModelState.IsValid)
            {
                XSSFWorkbook wb = context.GetReport(model);
                //I have no idea what to return after I got my wb
            }

            return View();
        }
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激。

asp.net-mvc excel npoi asp.net-mvc-5

5
推荐指数
1
解决办法
9715
查看次数

使用 NPOI 更新 Excel 文件中的现有单元格值

我创建了一个 Excel 文件,并在 (0,0) [row,cell] 中插入了一个新值作为Hello。第二次我打开同一个 Excel 文件、同一个工作表并用另一个字符串值更新同一个 (0,0) 单元格。

代码运行成功,没有任何错误,但文件已损坏且无法打开。

代码

namespace PractiseProject
{
    public static class ExcelNPOI
    {
        static IWorkbook workbook;
        static ISheet sheet;
        static IRow row;
        static ICell cell;
        static string file = "C:/Users/MSTEMP/Documents/Files/Test.xlsx";
        static string sheetName = "Testcase";

        public static void createExcel()
        {
            string firstValue = "Hello";
            if (!File.Exists(file))
            {
                using (FileStream str = new FileStream(file, FileMode.Create, FileAccess.Write))
                {
                    workbook = new XSSFWorkbook();
                    sheet = workbook.CreateSheet(sheetName);
                    row = sheet.CreateRow(0);
                    cell = row.CreateCell(0);
                    cell.SetCellValue(firstValue);
                    workbook.Write(str); …
Run Code Online (Sandbox Code Playgroud)

.net apache excel npoi c#-3.0

5
推荐指数
1
解决办法
7974
查看次数

如何使用 xssfworkbook npoi 在字体中设置 RGB 颜色

如何使用 npoi在cell backgroudn使用类中设置 RGB 颜色xssfworkbook

byte[] rgb = new byte[3] { 192, 50, 90 };
XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)wb.CreateCellStyle();
HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(new Color(255, 255, 255)));
Run Code Online (Sandbox Code Playgroud)

我不想使用这种模式:

titlestyle.BottomBorderColor = IndexedColors.Grey25Percent.Index;
Run Code Online (Sandbox Code Playgroud)

c# rgb background colors npoi

5
推荐指数
1
解决办法
6304
查看次数

NPOI以相同的方式格式化所有单元格

请查看以下代码段.我只是打开excel文件,myfile.xlsx然后从类型的对象List<Account>(我的Account对象只有Date,AccountAmount属性)添加行,并使用名称存储文件myoutputfile.xlsx.我希望我写日期的单元格具有日期格式,而我所拥有的单元格则具有数字格式.但是,如果我尝试下面的代码,所有单元格都格式化#.00(日期也是如此).我已经尝试了一切,有人可以告诉我发生了什么事吗?我正在使用NPOI.

    XSSFWorkbook wb;
    var fileName = "C:/tmp/myfile.xlsx";
    var outputFileName = "C:/tmp/myoutputfile.xlsx";
    using (var file = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite))
    {
        wb = new XSSFWorkbook(file);
    }

    XSSFSheet sheet = (XSSFSheet) wb.GetSheetAt(0);
    for (int i = 0; i < accountRecs.Count(); ++i) {
        var rec = accountRecs[i];
        var row = sheet.CreateRow(i);
        var dateCell = row.CreateCell(3);
        dateCell.SetCellValue(rec.Date);
        dateCell.CellStyle.DataFormat = wb.CreateDataFormat().GetFormat("dd/MM/yyyy");
        var accountCell = row.CreateCell(4);
        accountCell.SetCellValue(rec.Account);
        var totalValueCell = …
Run Code Online (Sandbox Code Playgroud)

c# excel npoi

5
推荐指数
1
解决办法
864
查看次数

如何在 C# 中使用 NPOI Excel 添加单元格注释?

我想在 C# 中使用 NPOI Excel 创建一个单元格注释。我没有找到任何明确的文件。我自己写的东西如下。

NPOI.HSSF.Record.NoteRecord nr = new NPOI.HSSF.Record.NoteRecord();
nr.Author = "Some Author";
NPOI.HSSF.Record.TextObjectRecord tor = new NPOI.HSSF.Record.TextObjectRecord();
tor.Str = new HSSFRichTextString("something");

HSSFComment cm = new HSSFComment(nr, tor);
cm.Visible = true;

sheet.GetRow(i).Cells[k + 8].CellComment = cm;   
Run Code Online (Sandbox Code Playgroud)

该代码无法正常工作。我在生成的 excel 文件中看不到对该单元格的任何评论。有没有人知道如何在特定单元格中添加评论?

c# excel comments cell npoi

5
推荐指数
1
解决办法
2442
查看次数

NPOI C# 将列设置为适合一页

我在我的 C# 应用程序中使用 NPOI 版本 2.5.3 并尝试设置缩放选项(在 1 页上适合所有列)。从这里这里的这些问题中,这似乎很容易做到。

问题:

因此,使用下面的代码时会出现我的问题。所做的只是配置;适合一页的宽度和高度。我认为这是因为sheet.FitToPage = true

private void SetPrintSettings(XSSFSheet sheet)
{
    sheet.SetMargin(MarginType.BottomMargin, 0.5);
    sheet.SetMargin(MarginType.TopMargin, 0.5);
    sheet.SetMargin(MarginType.LeftMargin, 0.45);
    sheet.SetMargin(MarginType.RightMargin, 0.45);
    sheet.SetMargin(MarginType.HeaderMargin, 0.3);
    sheet.SetMargin(MarginType.FooterMargin, 0.3);

    sheet.Autobreaks = true; //auto breaks
    sheet.FitToPage = true;  //THIS SETS IT TO ALL FIT ON ONE PAGE

    var PrintSetup = sheet.PrintSetup;
    PrintSetup.FitWidth = 1; //fit width onto 1 page
    PrintSetup.FitHeight = 0; //don't care about height
    PrintSetup.Landscape = true;
    PrintSetup.PaperSize = 3; …
Run Code Online (Sandbox Code Playgroud)

c# apache-poi npoi

5
推荐指数
1
解决办法
180
查看次数

标签 统计

npoi ×10

c# ×7

excel ×5

apache-poi ×2

.net ×1

apache ×1

asp.net-mvc ×1

asp.net-mvc-5 ×1

background ×1

c#-3.0 ×1

cell ×1

colors ×1

comments ×1

corrupt ×1

html ×1

rgb ×1

xls ×1

xlsx ×1