wordpress hit counter
Re: Problem with methods access of System.Collections.Generic.IEnumerable(Of DocumentFormat.OpenXml.Spreadsheet.Sheet) - SpreadsheetML - Formats - OpenXML Developer

Re: Problem with methods access of System.Collections.Generic.IEnumerable(Of DocumentFormat.OpenXml.Spreadsheet.Sheet)

Formats

Discussions about working with different Open XML Formats

Problem with methods access of System.Collections.Generic.IEnumerable(Of DocumentFormat.OpenXml.Spreadsheet.Sheet)

  • rated by 0 users
  • This post has 2 Replies |
  • 1 Follower
  • Hi Guys,

    I am gettings this compiler error:

    Compiler Error Message: BC30456: 'Where' is not a member of 'System.Collections.Generic.IEnumerable(Of DocumentFormat.OpenXml.Spreadsheet.Sheet)'.

    On other pages the MS excel works fine so I doubt the .dll is borken or something.
    if I replace the "where" with firstOrDefault or ElementAt(0) its the same error.

     
    1. Imports System.Data.SqlClient   
    2. Imports System.Net.Mail   
    3. Imports DocumentFormat.OpenXml   
    4. Imports DocumentFormat.OpenXml.Packaging   
    5. Imports DocumentFormat.OpenXml.Spreadsheet   
    6. Imports System.IO   
    7.   
    8. Partial Class BusinessLogic_Sent_Reminders   
    9.     Inherits System.Web.UI.Page   
    10.     Dim DA_Layer As New AFT_PPS_R2.DA_Layer   
    11.   
    12.     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load   
    13.         Response.ClearHeaders()   
    14.         Response.ClearContent()   
    15.         Response.Clear()   
    16.         Response.Buffer = True  
    17.   
    18.         'Open MS Excel template   
    19.         Dim sourceBytes() As Byte = File.ReadAllBytes(Me.MapPath("~\TemplateDocs\Gddddd.xlsx"))   
    20.         Dim ms As New MemoryStream   
    21.         ms.Write(sourceBytes, 0, sourceBytes.Length)   
    22.   
    23.         Using myWorkbook As SpreadsheetDocument = SpreadsheetDocument.Open(ms, True)   
    24.             Dim wbPart As WorkbookPart = myWorkbook.WorkbookPart   
    25.             Dim sheet = wbPart.Workbook.Descendants(Of Sheet)().Where(Function(s) s.Name = "test").FirstOrDefault   
    26.             Dim worksheetPart As WorksheetPart = DirectCast(myWorkbook.WorkbookPart.GetPartById(sheet.Id), WorksheetPart)  
  • Try adding the below line

    using System.Linq;

    Thanks

    Arun

  • Hi metalray,

    Not sure why you are seeing the error you are seeing.  I modified your code slightly so I could put into a module:

    Imports System.Data.SqlClient
    Imports System.Net.Mail
    Imports DocumentFormat.OpenXml
    Imports DocumentFormat.OpenXml.Packaging
    Imports DocumentFormat.OpenXml.Spreadsheet
    Imports System.IO
    
    Module Module1
    
        Sub Main()
            'Open MS Excel template   
            Dim sourceBytes() As Byte = File.ReadAllBytes("~\TemplateDocs\Gddddd.xlsx")
            Dim ms As New MemoryStream
            ms.Write(sourceBytes, 0, sourceBytes.Length)
    
            Using myWorkbook As SpreadsheetDocument = SpreadsheetDocument.Open(ms, True)
                Dim wbPart As WorkbookPart = myWorkbook.WorkbookPart
                Dim sheet = wbPart.Workbook.Descendants(Of Sheet)().Where(Function(s) s.Name = "test").FirstOrDefault
                Dim worksheetPart As WorksheetPart = DirectCast(myWorkbook.WorkbookPart.GetPartById(sheet.Id), WorksheetPart)
            End Using
        End Sub
    
    End Module
    
    It compiles without an error.  Can you give a bit more info?

    -Eric

Page 1 of 1 (3 items)