23
靜靜靜靜靜靜靜 靜靜靜 1 Web Component: Accessing the Web and CS V 靜靜靜靜靜靜靜 靜靜靜

Web Component: Accessing the Web and CSV 靜宜大學資管系 楊子青

  • Upload
    vlad

  • View
    88

  • Download
    0

Embed Size (px)

DESCRIPTION

Web Component: Accessing the Web and CSV 靜宜大學資管系 楊子青. 1. CSV. Ccomma-Separated Values 格式 ( 逗點分隔值 ) 一種文字檔格式,可用來在應用程式之間交換試算表的資料。 檔案中的每一行都代表試算表中的一列 試算表中的每一個儲存格通常以逗點區隔。不過也可使用其他字元來區隔欄位,例如,跳格字元。. 建立 CSV 實例. 開啟記事本,輸入一列資料,每個欄位以逗點隔開,存檔 ( 例如 test1.csv) 存檔前,存檔類型,請先選擇:所有檔案. 將 CSV 上傳至網頁空間. - PowerPoint PPT Presentation

Citation preview

Page 1: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 1

Web Component: Accessing the Web and CSV

靜宜大學資管系 楊子青

Page 2: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 2

1. CSV

• Ccomma-Separated Values 格式 ( 逗點分隔值 )– 一種文字檔格式,可用來在應用程式之間交換試算表的資料。

– 檔案中的每一行都代表試算表中的一列– 試算表中的每一個儲存格通常以逗點區隔。不過也可使用其他字元來區隔欄位,例如,跳格字元。

Page 3: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 3

建立 CSV 實例

• 開啟記事本,輸入一列資料,每個欄位以逗點隔開,存檔 ( 例如 test1.csv)– 存檔前,存檔類型,請先選擇:所有檔案

Page 4: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 4

將 CSV 上傳至網頁空間

• 例如上傳至 kitty.cs.pu.edu.tw

• 下載,並 Double click 開啟看看: http://www.cs.pu.edu.tw/~tcyang/test1.csv

Page 5: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 5

2. 讀取 CSV 內容之程式設計

• 使用者介面設計

Page 6: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 6

程式碼

Page 7: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 7

執行結果

Page 8: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 8

(1) 若讀不到檔案

Page 9: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 9

判斷是否成功讀取 CSV 檔之程式碼

Page 10: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 10

(2) 讀取 CSV 多筆資料→ OK

Page 11: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 11

(3) 輸入中文則發生亂碼

Page 12: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 12

解決方法:存檔時,編碼請選 UTF-8

Page 13: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 13

(4) 讀取 CSV 個別值,至二維陣列

Page 14: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 14

(4) 讀取 CSV 個別值,至二維陣列

Page 15: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 15

從二維陣列,讀取第 2 筆記錄

Page 16: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 16

從二維陣列,讀取第 1 筆第 4 欄

Page 17: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 17

從二維陣列,讀取每筆第 4 欄

Page 18: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 18

3. 實例應用: Yahoo 股市即時股價• http://tw.stock.yahoo.com/

– 輸入股票代號,例如 2330 台積電

Page 19: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 19

股票代號查詢

Page 20: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 20

Yahoo 股市提供的查詢網址• http://www.gummy-stuff.org/Yahoo-data.htm

Page 21: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 21

輸入網址, Yahoo 自動產生對應 CSV

• http://finance.yahoo.com/d/quotes.csv?f=ghl1&s=2330.tw– f 後的參數

• g 當日最低點 , h 當日最高點 , l1 ( 前一碼是 L 小寫 ) 成交價– s 後的參數: 2330 股市代號 , .tw 台灣股市

Page 22: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 22

練習:撰寫程式,即時查詢股價

Page 23: Web Component:  Accessing the Web and CSV 靜宜大學資管系  楊子青

靜宜大學資管系 楊子青 23

參考程式碼及執行實例