none
Worksheets were not processed as expected RRS feed

  • Question

  • Hi,

    Using these

                    var ExcelObj = new Excel.Application();
                    //Excel.Workbook Book0 = ExcelObj.Workbooks.Open(openFileDialog1.FileName, 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true);
                    ExcelObj.ScreenUpdating = false;
    
                    Excel.Worksheet Worksheet0;
    
                    using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, false))
                        {
                            WorkbookPart workbookPart = doc.WorkbookPart;
    
                            /*Sheet theSheet = workbookPart.Workbook.Descendants<Sheet>().
                                Where(s => s.Name == "Sheet Overall").FirstOrDefault();*/
                            Sheet theSheet;
    
                            int sheetIndex = 0;
                            DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = workbookPart.Workbook.Sheets;
                            //foreach (WorksheetPart wsPart in workbookPart.WorksheetParts)
                            foreach (Sheet sheet in sheets)
                            {
                                //WorkbookStylesPart wstylePart = workbookPart.WorkbookStylesPart;
                                //Stylesheet ss = wstylePart.Stylesheet;
    
                                using (StreamWriter sw = new StreamWriter(@File1, true, Encoding.Unicode))
                                {
                                    sw.WriteLine(" {0} rId is {1},sheetId is {2}", sheet.Name, sheet.Id, sheet.SheetId);
                                }
    
                                string sheetPartType = workbookPart.GetPartById(sheet.Id).GetType().Name;
                                if (sheetPartType != "WorksheetPart")
                                {
                                    //Console.WriteLine("{0} is not a worksheet", sheet.Name);
                                    using (StreamWriter sw = new StreamWriter(@File1, true, Encoding.Unicode))
                                    {
                                        sw.WriteLine("{0} is not a worksheet", sheet.Name);
                                    }
                                }
                                else
                                {
                                    WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById(sheet.Id);
                                    WorkbookStylesPart wstylePart = workbookPart.WorkbookStylesPart;
                                    Stylesheet ss = wstylePart.Stylesheet;
    
                                    foreach (Cell cell in worksheetPart.Worksheet.Descendants<Cell>())
                                    {
                                        if (cell.StyleIndex != null)
                                        {
                                        ...



    it does not show details of Worksheets like
    201601
    201602
    201603
    201604
    201605

    when I run the codes against this.


    Many Thanks & Best Regards, Hua Min

    Monday, September 26, 2016 6:42 AM

Answers

  • Hi,

    Using the code above and your file, I could retrieve as


    If other sheets could be printed successfully , do you operate these five sheets using other part of code in your project?

    I suggest you test this code snippet separately and check if it could be printed.



    Tuesday, September 27, 2016 1:24 AM
    Moderator

All replies

  • Hi,

    Using the code above and your file, I could retrieve as


    If other sheets could be printed successfully , do you operate these five sheets using other part of code in your project?

    I suggest you test this code snippet separately and check if it could be printed.



    Tuesday, September 27, 2016 1:24 AM
    Moderator
  • What should be the conflicts? Do you mean to specifically to test against these few sheets I mentioned?

    Many Thanks & Best Regards, Hua Min

    Tuesday, September 27, 2016 2:02 AM
  • What details information do you want to get for the five sheets? For the code below, I think it would successfully print Sheet.Name, sheet.id and  sheet rId since it loops for each sheet.

    Tuesday, September 27, 2016 5:34 AM
    Moderator
  • Hi,

    It seems that you did not set any Border styles for these sheets, all the cellstyleIndex is null.

    Please set one for them and check if the code could successfully retrieve value.

    Tuesday, September 27, 2016 10:27 AM
    Moderator