读取EXCEL

            using (FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read))

            {

                HSSFWorkbook workbook = new HSSFWorkbook(fs);

                HSSFSheet sheet1 = (HSSFSheet)workbook.GetSheetAt(0);





                using (FileStream csv = new FileStream(outputFile, FileMode.Create, FileAccess.Write))

                {

                    using (StreamWriter write = new StreamWriter(csv, Encoding.UTF8))

                    {

                        for (int i = sheet1.FirstRowNum; i < sheet1.LastRowNum; i++)

                        {

                            HSSFRow row = (HSSFRow)sheet1.GetRow(i);

                            if (row == null)

                                continue;

                            string content = "";

                            for (int j = row.FirstCellNum; j < row.LastCellNum; j++)

                            {

                                HSSFCell cell = (HSSFCell)row.GetCell(j);

                                if (cell == null)

                                    continue;

                                content += cell.ToString().Replace("\n", "") + ",";

                            }

                            content = content.Substring(0, content.Length - 1);

                            write.WriteLine(content);

                        }



                    }



                }

 

你可能感兴趣的:(Excel)