2011-11-23 61 views
0

如何在Excel文檔中用c#搜索合併單元格?如何搜索Excel文件中的合併單元格

我想以一致的方式操作合併的單元格,但我必須知道他們的地址才能這樣做。

我有幾百個,因爲缺少一個更好的單詞,Excel中的表格並且每個表格上都有合併的單元格,我必須移動並放在每個表格的右側。

爲此,我需要知道如何搜索合併的單元格,並使用C#獲取合併單元格的地址。我目前正在使用Interop。

此外,如果你認爲有更簡單的方法,在excel中具有基本的excel功能,請讓我知道。

感謝您的任何幫助。

回答

0

如果您使用的是詢問服務的Office Open XML的新的Office產品,你可能可以解析XML和發現,代表合併單元格

以下的電子標籤是一種片與2個單元一個從A1合併的例子-b1和一個單元格a2。

有一些商業和可能的一些開源解決方案,可以簡化xml處理。

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"> 
    <dimension ref="A1:B2"/> 
    <sheetViews> 
     <sheetView tabSelected="1" workbookViewId="0"> 
      <selection activeCell="A2" sqref="A2"/> 
     </sheetView> 
    </sheetViews> 
    <sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/> 
    <sheetData> 
     <row r="1" spans="1:2" x14ac:dyDescent="0.25"> 
      <c r="A1" s="1" t="s"> 
       <v>0</v> 
      </c> 
      <c r="B1" s="1"/> 
     </row> 
     <row r="2" spans="1:2" x14ac:dyDescent="0.25"> 
      <c r="A2" t="s"> 
       <v>1</v> 
      </c> 
     </row> 
    </sheetData> 
    <mergeCells count="1"> 
     <mergeCell ref="A1:B1"/> 
    </mergeCells> 
    <pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/> 
</worksheet> 
+0

任何人都沒有xml的方式嗎?我現在沒有時間去研究這個問題,因爲這個問題很快就會到期。不過,我相信現在可能是現在的路,因爲Interop太老了。 –

相關問題