2012-02-13 4 views
1

나는 다음과 같은 코드가 있습니다OPENXML

public static void ReadExcelFileSAX(string filename) 
{ 
     using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(filename, true)) 
     { 
      WorkbookPart workbookPart = myDoc.WorkbookPart; 
      WorksheetPart worksheetPart = workbookPart.WorksheetParts.First(); 

      OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); 
      string text; 
      while (reader.Read()) 
      { 
       if (reader.ElementType == typeof(CellValue)) 
       { 
        text = reader.GetText(); 
       } 
      } 
     } 
} 

데이터 유형이 숫자 셀을 읽을 수있는이 코드 만 읽을 수없는 inlineStr

을 생산성 도구를 사용하여 XML을 보면, I (또는 내가 알것하지 않는 코드는 다음 XML

<x:c r="D2" t="n"> 
    <x:v>328</x:v> 
    </x:c> 

를 읽을 수 있지만 그것은이 하나를 읽을 수있을 것 같아요 어떻게 해야할지)

<x:c r="F1" s="6" t="inlineStr"> 
     <x:is> 
      <x:t>T1</x:t> 
     </x:is> 
     </x:c> 

도움이 되겠습니다. 제대로 값을 읽어야하지만, 좀 더 많은 정보는 문제의 원인을 발견하는 것이 유용 할 것 같은

덕분에

+0

당신이 오류를 얻거나 inlineStr 값을 읽을 때 그냥 빈 문자열을받을 수 있나요? –

답변

2

에 코드를 봐. InlineStringOpenXMlLeafTextElement에서 dervide되지 않기 때문에

나는, 당신은 유형 InlineString 있는지 확인하려고 할 수 있지만 그냥 GetText() 방법을 사용할 수 없습니다 가정합니다.

나는 아직 테스트하지 않은,하지만 난 당신이 시도하는 것이 좋습니다 : 이와 비슷한

while (reader.Read()) 
{ 
    if (reader.ElementType == typeof(CellValue)) 
    { 
     text = reader.GetText(); 
    } 
    else if (reader.ElementType == typeof(InlineString)) //or instead of this, check type of its child node and use it inside this if statement 
    { 
     text = (reader.LoadCurrentElement() as InlineString).Text.Text; 
    } 
} 

또는 무언가를. 이 코드에 문제가 있으면 알려 주시기 바랍니다.

일부 참조 :

+0

도움이 된 것을 기쁘게 생각합니다. –