Re: [問題] 取得Excel的所有sheet

看板C_Sharp作者 (懶)時間16年前 (2009/06/29 23:55), 編輯推噓2(202)
留言4則, 3人參與, 最新討論串2/2 (看更多)
不好意思,又有問題想請教一下 我要如何去取得目前使用中的sheet的column和row的數目? 下面是我的code,不過取出來的columns.count都是256 謝謝 public string[] GetSheetHeader() { string[] header = new string[excelWorksheet.Columns.Count]; Excel.Range oRange = null; int i = 0; if (this.excelSheets != null) { for (i = 0; i < excelWorksheet.Columns.Count; i++) { oRange = excelApp.get_Range(excelApp.Cells[1, i + 1], excelApp.Cells[1, i + 1]); header[i] = oRange.Value2.ToString(); } } return header; } -- ╔╮ ╭═╦╮╭═╦╗╮ ╮╔══╮╭═╦╮╮ ╔╮╔══╮╭══╮ ╠╣ ╠═╬╣╭╬╩╯╰╦╦╯╠═╦╮║ ╠╣║║╠╣╠╣ ╰═╦╮ ╠╣ ╭║ ╠╣║╰╔╗ ╠╣ ║ ╠╣║ ╠╣║╰╠╣║╰╔╗║ ╠╣ ╰╩═╯╰ ╰╝╚═╩╯ ╰╝ ╚═╩╯╰═╩╯╰ ╰╝╚═╩╯╰═╩╯ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.20.144.252

06/30 00:03, , 1F
excelWorksheet.UsedRange.Columns.Count
06/30 00:03, 1F

06/30 00:52, , 2F
謝謝!!
06/30 00:52, 2F

06/30 11:23, , 3F
再請教一下 若是要取得某row的column數 要用什麼?
06/30 11:23, 3F
※ 編輯: lazybones 來自: 210.69.124.17 (06/30 15:59)

07/06 00:24, , 4F
假設row I => Range.rows[i].columns.count
07/06 00:24, 4F
文章代碼(AID): #1AIEFeOd (C_Sharp)
文章代碼(AID): #1AIEFeOd (C_Sharp)