C# NPOI 无法将 FileInputStream 变量分配给 XSSFWorkbook 变量

C# NPOI cannot assign FileInputStream variable to XSSFWorkbook variable

所以我将 C# 与 NPOI 包一起使用,并尝试将我的文件分配给要读取的 XSSF 工作簿变量,但我收到以下错误

这里是相关的代码片段

private static XSSFWorkbook workbook;

        //  runs the console, which runs the gogo()
        public static void main(String[] args)
        {
            Console.run2();   
        }

        public void gogo()
        {

            FileInputStream excelFile;
            try
            {
                //  get the file and assign it to excelFile
                excelFile = new FileInputStream(new File(FileName.getFile()));

                //  open up the excelfile workbook
                workbook = new XSSFWorkbook(excelFile);

                //  get the # of sheets in the workbook for iterator
                this.lastSheet = workbook.getNumberOfSheets();

XSSFWorkbook ctor 接受 Stream 作为它的参数。但是,FileInputStream 不会扩展 Stream(也不能隐式转换)。解决问题的一种方法是使用 FileStream 而不是 FileInputStream。例如:

FileStream excelFile = File.OpenRead(FileName.getFile());