BatchDelete/ExcelUtils.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BatchDelete
{
    static class ExcelUtils
    {
        class CellValue
        {
            public Cell cell;
            public string value;
            public int rowIndex;
            public int colIndex;
        }

        public static async Task<List<string[,]>> LoadData(string path)
        {
            List<string[,]> result = new List<string[,]>();
            //if (stream != null)
            {
                string value = null;
                /*if (System.IO.File.Exists(file.Path))
                {
                    string str = System.IO.File.ReadAllText(file.Path);
                    await (new MessageDialog(str.Length.ToString())).ShowAsync();
                }*/
                //Stream stream = await file.OpenStreamForReadAsync();
                // Open the spreadsheet document for read-only access.
                using (SpreadsheetDocument document = 
                    SpreadsheetDocument.Open(path, false))
                {
                    // Retrieve a reference to the workbook part.
                    WorkbookPart wbPart = document.WorkbookPart;

                    // Find the sheet with the supplied name, and then use that 
                    // Sheet object to retrieve a reference to the first worksheet.
                    Sheet[] sheets = wbPart.Workbook.Descendants<Sheet>().ToArray();
                    for (int k = 0; k < sheets.Length; k++)
                    {
                        List<CellValue> cellValues = new List<CellValue>();
                        string[,] datas;
                        Sheet theSheet = sheets[k];

                        // Throw an exception if there is no sheet.
                        if (theSheet == null)
                        {
                            throw new ArgumentException("sheetName");
                        }

                        // Retrieve a reference to the worksheet part.
                        WorksheetPart wsPart =
                            (WorksheetPart)(wbPart.GetPartById(theSheet.Id));
                        var stringTable = wbPart.GetPartsOfType<SharedStringTablePart>().FirstOrDefault();
                        // Use its Worksheet property to get a reference to the cell 
                        // whose address matches the address you supplied.
后面还有 112 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。