如何关闭由spire.xls创建的文件

时间:2018-07-11 09:53:43

标签: c# spire.xls

我正在使用Spire.XLS将CSV文档转换为PDF,如代码所示。 问题在于,文件在创建后仍处于打开状态,并且在程序运行时无法删除它。那么有人知道我如何在不关闭钻孔程序的情况下关闭该文件吗?

//check if open = false
        if (IsFileinUse())
        {
            Console.WriteLine("PDF open btn_ConvertToPDF_Click");
        }
        else
        {
            Console.WriteLine("PDF closed btn_ConvertToPDF_Click");
        }

        //code that creates the file but does not close it
        Workbook wb = new Workbook();
        wb.LoadFromFile(filename + ".csv", ",");
        wb.ConverterSetting.SheetFitToPage = true;
        Worksheet sheet = wb.Worksheets[0];
        for (int i = 1; i < sheet.Columns.Length; i++)
        {
            sheet.AutoFitColumn(i);
        }
        sheet.SaveToPdf(filename+".pdf");

        //check if open = true
        if (IsFileinUse())
        {
            Console.WriteLine("PDF open btn_ConvertToPDF_Click");
        }
        else
        {
            Console.WriteLine("PDF closed btn_ConvertToPDF_Click");
        }

0 个答案:

没有答案