C # for Excel sheet name in its table contents

2010-06-02  来源:本站原创  分类:DotNet  人气:264 

public static DataTable GetExcelTable(string excelFilename)
{
    string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=35;Extended Properties=Excel 8.0;Persist Security Info=False",excelFilename);
    DataSet ds = new DataSet();
    string tableName;
    using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))
    {
        connection.Open();
        DataTable table = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
        tableName = table.Rows[0]["Table_Name"].ToString();
        string strExcel = "select * from " + "[" + tableName + "]";
        OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, connectionString);
        adapter.Fill(ds, tableName);
        connection.Close();
    }
    return ds.Tables[tableName];
}
相关文章
  • C # for Excel sheet name in its table contents 2010-06-02

    public static DataTable GetExcelTable(string excelFilename) { string connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Engine Type=35;Extended Properties=Excel 8.0;Persist Security Info=False",excelFile

  • ec label associated with multi-table query results to export excel sheet as a blank solution 2010-02-03

    When the query data needs two or more tables associated with the table when the query results, you can use a query as follows: getSession (). createQuery ( "select new map (pm.name as name1, pm.sex as sex1, pmm.oldOrgName as oldOrgName1, pmm.id as id

  • Export the report to run dry more than one page excel sheet in the different 2010-10-20

    Run-dry statements as statements of editing tools very easy to use, simply set the properties can be achieved, export, print and other functions (see Run Dry development and application of specific documents), it is very depressing that export only a

  • [Transfer] POI operate using Excel: Sheet copy 2011-07-25

    Many of the project modules need to export data to Excel, the simple, such as export all the user information to Excel, the export of such data, you can POI / JXL can directly generate Excel; when faced with complex formatting reports how to do it? B

  • leetcode 171: Excel Sheet Column Number 2015-02-03

    Related to question Excel Sheet Column Title Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 public class Solution { public int tit

  • ASP.NET page methods of data export excel sheet 2010-08-13

    //1. Dataset generated by the public void CreateExcel(DataSet ds,string typeid,string FileName) { HttpResponse resp; resp = Page.Response; resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); resp.AppendHeader("Content-Disposi

  • Excel sheet into a database on a little bit of experience 2010-10-25

    A few days ago, the school site to a group of students I import the data, relatively large amount of data, the morning train to excel table into sql file conversion process, the operation is relatively simple, but if you use the php file to change it

  • PHP how to excel data into the database table 2010-12-15

    Recently because of development needs, make a lot of data into a software database to do the test before use real data to make use of the data into excel in the database. Let's directly into the following question: I was Thinkphp developed under the

  • sql export excel sheet 2010-11-14

    In the mysql command line to export the data into excel file (. Xls format) Date from 2009 -08-28: Internet Views: 1265 In the mysql command line to export the data into excel file (. Xls format): In the mysql command line, execute the following sql

  • Select data from an Excel sheet in MSSQL 2013-12-17

    select * from openrowset('Microsoft.Jet.OLEDB.4.0' ,'Excel 8.0;HDR=YES;IMEX=1;DATABASE=d:\folder\excel.xls',Sheet1$) -------NOTE------ Setting IMEX=1 tells the driver to use Import mode. In this state, the registry setting ImportMixedTypes=Text will

  • Five main functions of web reporting tools comparison 2010-03-28

    Original: http://ibaobiao.com/archives/132 Company doing the project, the need to use reporting tools, after the mainstream market, we report a series of inspection tools, integrated assessment, and reporting tool vendors to some field trips. We chos

  • Transfer: Javascript to achieve the contents of the page table to export to excel in several ways 2010-06-16

    1. direct copy the entire table to EXCEL In 2. by walking the form , To Excel in the assignment . 3. the table of contents extracted , Take advantage of IE's save as .csv The format of . The benefits of the various methods : 1. Direct copy form, bein

  • java excel table operation 2010-07-05

    About Java Excel JAVA EXCEL API is an open source project through which Java developers can read Excel document, create a new Excel file, update Existing Excel file. Non-Windows operating system using the API can also be pure Java application to hand

  • html table Excel Export 2010-09-19

    <table border="1" cellspacing="0" cellpadding="0"> <tr> <th> The first column </th> <th> The second column </th> <th> The third column </th> <th> The fourth column </th

  • PHP生成Excel,支持多个Sheet 2013-10-28

    php-excel.class.php: <?php class WorkSheet { private $lines = array(); public $sWorksheetTitle; public function __construct($sWorksheetTitle) { $this->setWorksheetTitle($sWorksheetTitle); } public function setWorksheetTitle ($title) { $title = preg_

  • java generated Excel 2009-07-22

    java generated Excel Java generated by Excel is very simple to use the JExcelAPI here and MySql driver package, package-related jar and source files have been uploaded by myself downloaded the following steps: 1. Be downloaded unzip the file compress

  • Operation EXCEL file using JAVA 2010-03-29

    JAVA EXCEL API Introduction Java Excel is an open source project, through which Java developers can read Excel document, create a new Excel file, update an existing Excel file. Of non-Windows operating system using the API can also be a pure Java app

  • Jxl generated using Excel 2010-03-29

    jxl installation: Jxl package is mainly placed on the WEB-INF of the classes below (if the download is. Jar file, placed lib below). Do not forget to jxl package in the common folder is also on the WEB-INF below. jxl of use: The main function is to r

  • jxl Operation excel (merged cells, set the background color, font color) 2010-04-18

    The project is being done now involves a large number of Excel files export import operations are using the Java Excel to operate. Java Excel is an open source project, through which Java developers can read Excel document, create a new Excel file, u

  • 2010.03.12 (3) - large data export excel the html 2009-12-22

    2010.03.12 (3) - large data export excel the html package test; import java.io.FileOutputStream; import java.io.OutputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.text.SimpleDateFormat; import