天天看點

php讀取網頁中表格資料庫,網頁中讀取excel顯示表格資料庫-利用EXCEL表格為資料庫制作查詢網頁...

做一個網頁 網頁上有一個功能是直接将excel表直接...

如果要了php輸出excel格式檔案就必須利用header content-type:application/vnd.ms-excel來實作。如下

$filename = name .'.xls';

header("content-type:application/vnd.ms-excel");

header("content-disposition:attachment;filename=$filename");

?>

再看一php輸出excel執行個體

header("content-type:application/vnd.ms-excel");

header("content-disposition:filename=test.xls");

echo "a1tb1tc1tna2ta3ta4tn";//r t單元格,n新一行

?>

require_once("../../config/sys_config.php"); //配置檔案

require_once("../../include/db_class.php");

header("content-type: text/html; charset=$page_code"); //頁面編碼

header("content-type:application/vnd.ms-excel");

header("content-disposition:attachment;filename=".mb_convert_encoding("客戶報表","gbk",$page_code).".xls");

header("pragma:no-cache");

header("expires:0");

//$usersid = intval( $_get['uid'] ); //使用者id

//輸出内容如下:

// 輸出表頭

echo iconv("utf-8", "gb2312", "客戶名稱")."t";

echo iconv("utf-8", "gb2312", "電話")."t";

echo iconv("utf-8", "gb2312", "位址")."t";

echo iconv("utf-8", "gb2312", "添加日期")."t";

echo "n"; //換行

$sqlstr = "select * from clients where usersid=32 order by clientsid desc";

$rows = $db -> select($sqlstr);

$num = count($rows); //客戶總數

for( $i = 0; $i < $num; $i )

{

echo iconv("utf-8", "gb2312",$rows[$i][clientsname])."t";

echo iconv("utf-8", "gb2312",$rows[$i][clientsphone])."t";

echo iconv("utf-8", "gb2312",$rows[$i][clientsaddress])."t";

echo iconv("utf-8", "gb2312",$rows[$i][clientstime])."t";

echo "n"; //換行

}

?>

利用EXCEL表格為資料庫制作查詢網頁

如果你用的ORACLE資料庫

1.打開PL/SQL dev

2.File—New——Report Window,在中間輸入你的SELECT語句,得到你表或視圖

3.在點選"Save as excel"或者"Save as HTML"就可以了!非常友善

希望能幫到你!

C#語言在網頁上将excel中的内容導入到SQL資料庫表中

Resource resource = new ClassPathResource("/applicationContext.xml");

BeanFactory factory = new XmlBeanFactory(resource);

SessionFactory sessionFactory = (SessionFactory) factory

.getBean("sessionFactory");

Session session = sessionFactory.openSession();

File excelfile = new File(ServletActionContext.getRequest()

.getRealPath("/upload")

"/" filepath);

Workbook book = null;

int rownum;

String mname = null;

try {

book = Workbook.getWorkbook(excelfile);

Sheet sheet = book.getSheet(0);// 工作簿是從0開始

for (rownum = 1; rownum < sheet.getRows(); rownum ) {

mname = sheet.getCell(0, rownum).getContents().trim();

String sql = "insert into media values (seq_media.nextval,?,?,?,?,?,?)";

Query query = session.createSQLQuery(sql);

query.setString(0, mname);

query.executeUpdate();

session.beginTransaction().commit();

}

} catch (Exception e) {

e.printStackTrace();

} finally {

book.close();

}

這個是我的代碼 希望幫到你 采納我 謝謝

如何把從資料庫讀出來的資料以excel格式顯示到網頁

Resource resource = new ClassPathResource("/applicationContext.xml");

BeanFactory factory = new XmlBeanFactory(resource);

SessionFactory sessionFactory = (SessionFactory) factory

.getBean("sessionFactory");

Session session = sessionFactory.openSession();

File excelfile = new File(ServletActionContext.getRequest()

.getRealPath("/upload")

"/" filepath);

Workbook book = null;

int rownum;

String mname = null;

try {

book = Workbook.getWorkbook(excelfile);

Sheet sheet = book.getSheet(0);// 工作簿是從0開始

for (rownum = 1; rownum < sheet.getRows(); rownum ) {

mname = sheet.getCell(0, rownum).getContents().trim();

String sql = "insert into media values (seq_media.nextval,?,?,?,?,?,?)";

Query query = session.createSQLQuery(sql);

query.setString(0, mname);

query.executeUpdate();

session.beginTransaction().commit();

}

} catch (Exception e) {

e.printStackTrace();

} finally {

book.close();

}

這個是我的代碼 希望幫到你 采納我 謝謝

你好! 請教你個問題 java web程式如何将讀取的exc...

就不上嘞太多。。。而且這東過一次就好嘞。。。

給你個思路。。。首先分解問題

1.java要讀取excel,就需要用到 上傳功能 怎麼傳搜度娘

2.java讀取excel 我用的是jxl這個jar 怎麼用搜度娘

3.插入資料庫 insert就好 考慮性能和效率 建議用批量

4.顯示在jsp select就好

關鍵的代碼 網上都有 複制改就好 但是規則一定要自己想好