Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. EXCEL Access

EXCEL Access

Scheduled Pinned Locked Moved C#
tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Ozgur
    wrote on last edited by
    #1

    Hi , How to access an EXCEL File and read the cells within it? Can anyone show me a light? thanks in advance

    L 1 Reply Last reply
    0
    • O Ozgur

      Hi , How to access an EXCEL File and read the cells within it? Can anyone show me a light? thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I never write c# code, but In c++ or java, I ever had access Excel, send the c++ codes, hope some help to you! ---------------------------------------------------------- package snsoftx.win; import snsoft.util.*; import com.jacob.com.*; import com.jacob.activeX.*; import java.util.*; import java.io.File; /** * Company: 南北公司 * @author: Grant * @email: wang_yi_ming@263.net * @version 5.0 * * MSExcelApp类用来操作Ms Excel文件: * 新建,删除文件, Sheet, Row, Col * comments: * 要使用MSExcelApp类, 必须jacob.dll的支持 * * expamples: * 1. 只读打开文件,读数据: * MSExcelApp excelApp = null; * try { excelApp = new MSExcelApp(); if( excelApp.openExcel("c:\\temp\\cc.xls","Sheet1") ) { int rowCount = excelApp.getRowCount(); int colCount = excelApp.getColumnCount(); System.out.println("rowCount=" + rowCount+",colCount=" + colCount); // get column info for (int col = 0; col < colCount; col++) System.out.println("colName:" + excelApp.getColumnName(col) + "\r\n"); excelApp.prepareFetchData(); // 为了提高查询速度 for (int r = 0; r < rowCount; r++) { excelApp.gotoRow( r ); for (int c = 0; c < colCount; c++) { Object ob = excelApp.getValue(c); // or ob = excelApp.getCellValue(r,c); s += (ob == null) ? "" : ob.toString() + ","; } System.out.println(s + "\r\n"); } excelApp.endFetchData(); excelApp.close(); } } catch (Exception ex) { ex.printStackTrace(); } * 2. 打开文件,修改文件 : * MSExcelApp excelApp = null; * try { excelApp = new MSExcelApp(); if( excelApp.openExcel("c:\\temp\\cc.xls","学生成绩单",false,false,true) ) { excelApp.addField("学号",0) excelApp.addField("姓

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups