2013-10-31 3 views
-1

Excel 통합 문서에서 데이터를 추출하여 작성한 xml 파일이 있습니다.xml 파일의 데이터를 Excel 통합 문서에 붙여 넣으십시오.

http://www.2shared.com/document/wbAYcQ4F/XMLTest.html

<?xml version="1.0"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40"> 
    <Styles> 
    <Style ss:ID="Default" ss:Name="Normal"> 
     <Alignment ss:Vertical="Bottom" /> 
     <Borders /> 
     <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000" /> 
     <Interior /> 
     <NumberFormat /> 
     <Protection /> 
    </Style> 
    <Style ss:ID="s16"> 
     <Borders> 
     <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" /> 
     <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" /> 
     <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="2" /> 
     </Borders> 
    </Style> 
    <Style ss:ID="s17"> 
     <Borders> 
     <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" /> 
     <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" /> 
     </Borders> 
    </Style> 
    <Style ss:ID="s18"> 
     <Borders> 
     <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="2" /> 
     <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="2" /> 
     <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="2" /> 
     </Borders> 
     <Interior ss:Color="#16365C" ss:Pattern="Solid" /> 
    </Style> 
    </Styles> 
    <Worksheet ss:Name="First Worksheet"> 
    <Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="9" ss:DefaultRowHeight="15"> 
     <Column ss:Index="3" ss:Width="54" /> 
     <Row ss:Height="15.75" /> 
     <Row> 
     <Cell ss:Index="3" ss:StyleID="s16"> 
      <Data ss:Type="Number">12345</Data> 
     </Cell> 
     </Row> 
     <Row> 
     <Cell ss:Index="3" ss:StyleID="s17" /> 
     </Row> 
     <Row> 
     <Cell ss:Index="3" ss:StyleID="s17"> 
      <Data ss:Type="String">Some Text</Data> 
     </Cell> 
     </Row> 
     <Row> 
     <Cell ss:Index="3" ss:StyleID="s17" /> 
     </Row> 
     <Row ss:Height="15.75"> 
     <Cell ss:Index="3" ss:StyleID="s18" /> 
     </Row> 
    </Table> 
    </Worksheet> 
</Workbook> 

XML 파일 I는 선택된 범위의 데이터를 포함한다. 워크 시트 이름 및 범위의 모든 값 및 서식 (색, 테두리 등)이 예제에서는 C 열만있는 셀, 문자열 및 색칠 된 셀이있는 셀 및 모든 데이터를 둘러싼 테두리가 있습니다. Excel로 파일을 열 때 추출 된 데이터를 정확하게 보여줍니다.

이제 Excel로 추출 할 수 있는지 알고 싶습니다. 모든 값과 서식을 프로그래밍 방식으로 지정하여 새 Excel 통합 문서에 붙여 넣으십시오. Excel에서 xml 파일을 열지 않는 것이 좋습니다.

미리 감사드립니다.

답변

0
XDocument doc = XDocument.Load("XMLFile1.xml"); 

var x= doc.Descendants("x"); 
var y= doc.Descendants("y"); 
object[,] z; 
Excel.Application ActiveExelAplication = Globals.ThisAddIn.Application as Excel.Application; 
Excel.Worksheet ExWorksheet = ActiveExelAplication.ActiveSheet as Excel.Worksheet; 
z= ExWorksheet.get_Range("v"+x[0].ToString() , "v" + y[1].ToString() as Excel.Range; 
+0

여기서 무엇을하려고하는지 잘 모르겠습니다. 파일을 다운로드 했습니까? xml 파일의 내용으로 초기 게시물을 편집했으며 x와 y는 자손이 아닙니다. 또한 x [0] 및 y [1]은 "형식이"System.Collections.Generic.IEnumerable "인 식에 []를 사용한 인덱싱을 적용 할 수 없습니다. – user2456733

관련 문제