將web中多控制項資料匯入到EXECL

2021-03-31 17:28:08 字數 3401 閱讀 5874

imports system.data

imports system.data.sqlclient

imports system.web.ui

public class webform1

inherits system.web.ui.page

#region " web 窗體設計器生成的** "

'該呼叫是 web 窗體設計器所必需的。

private sub initialize***ponent()

end sub

protected withevents radiobutton1 as system.web.ui.webcontrols.radiobutton

protected withevents rbutton as system.web.ui.webcontrols.radiobutton

protected withevents radiobutton2 as system.web.ui.webcontrols.radiobutton

protected withevents lblteacher as system.web.ui.webcontrols.label

protected withevents txtteacher as system.web.ui.webcontrols.textbox

protected withevents btnteacher as system.web.ui.webcontrols.button

protected withevents pnlteacher as system.web.ui.webcontrols.panel

protected withevents panel1 as system.web.ui.webcontrols.panel

protected withevents mydatagrid as system.web.ui.webcontrols.datagrid

protected withevents label1 as system.web.ui.webcontrols.label

protected withevents button2 as system.web.ui.webcontrols.button

'注意: 以下佔位符宣告是 web 窗體設計器所必需的。

'不要刪除或移動它。

private designerplaceholderdeclaration as system.object

private sub page_init(byval sender as system.object, byval e as system.eventargs) handles mybase.init

'codegen: 此方法呼叫是 web 窗體設計器所必需的

'不要使用**編輯器修改它。

initialize***ponent()

end sub

private sub page_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load

end sub

'讀取並繫結資料

public sub todatagrid(byval sqlstring as string, byval dtgrid as datagrid, byval tbdate as string, byval strgrid as string)

dtgrid.dispose()

sqlconnection.open()

dim sqlcmd as sqldataadapter = new sqldataadapter(sql, sqlconnection)

dim result as dataset = new dataset

sqlcmd.fill(result, "tbdate")

dim mytable as data.datatable = new data.datatable

mytable = result.tables("tbdate")

if mytable.rows.count >= 1 then

dim dr as data.datarow

dr = mytable.newrow()

dr(0) = "合計"

dr(1) = "數量"

dr(2) = "第三"

mytable.rows.add(dr)

end if

dtgrid.datasource = mytable

dtgrid.databind()

dtgrid.caption = strgrid

dim i as integer

'   i = dtgrid.columns.count()

i = mytable.rows.count

label1.text = "總記錄:" & i & "條" & "     統計時間" & format(now, "d")

sqlconnection.close()

end sub

'將datagrid中顯示的函式轉換到excel檔案中

private sub btnteacher_click(byval sender as system.object, byval e as system.eventargs) handles btnteacher.click

sql = "select right(ai.a_id,10) as **編號,ai.a_name as **名稱,ai.a_publiction as 發表刊物,o.o_name as 辦公室,ta.t_serial as 作者序號 from article_info ai,teacher_article ta,office o,teacher_info ti where ai.a_id in (select a_id from teacher_article where t_id ='100001') and ai.a_id = ta.a_id and ta.t_id = '100001' and ti.t_id = '100001' and ti.o_id = o.o_id"

dim s as string

s = "湖南商學院科研管理資訊系統教師個人科研**統計結果"

s += "

"s += "    " & "教師編號:" & trim(txtteacher.text)

todatagrid(sql, mydatagrid, "article_info", s)

end sub

private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click

toexcel(mydatagrid, label1)

end sub

end class

將DataGrid中的資料完全匯入到EXCEL中

今天晚上開始測試,以前做過一次,但是很不完美。大致 如下 匯入excel中,button的click事件 private void excel btn click object sender,system.eventargs e 如果有格式轉化問題,在itemdatabound事件中寫 if e.i...

將csv檔案資料匯入到 mysql

假如有格式統一的csv檔案,但是csv中的每個欄位都是不同格式的資料型別,可以用pandas,直接匯入,資料型別會自動識別 僅三行 coding utf 8 import pandas as pd from sqlalchemy import create engine df pd.read csv...

將資料匯入到Oracle中

1.create table people age int,id int 2.建立資料檔案peopledate.txt.資料為 20,1 30,2 3.建立命令檔案 loaddata.ctl 內容為 sqlldr userid dbname dbpasswd control loaddata.ctl...