星期四, 3月 26, 2015

如何鎖定 Excel 裡的固定欄位

step 1) 選取所要固定的欄位 (反白)
step 2) 按右鍵(下拉式選單)
step 3) click "儲存格格式"
step 4) open the "保護" tab
step 5) unlock "鎖定", then "確定"
step 6) 在左下角"工作表x"按右鍵(下拉式選單)
step 7) click "保護工作表"
step 8) unlock "選取鎖定的儲存格", then "確定"


星期四, 3月 19, 2015

Arduino 的環境下, 把 Array 寫入到 flash ; 而不是 SRAM

在 MCU 的 SRAM 有限情形下, 要把一些表格放置到 flash 的區域下,而非佔用 SRAM

const byte myArray[] =

{
   0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
   0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
   0x03,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
};

使用 PROGMEM 關鍵字, 同時

#include

const byte myArray[] PROGMEM=

{
   0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
   0x02,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
   0x03,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
};

在讀取時, 使用

pgm_read_byte_near(), ex:

int k;    // counter variable

char myChar; 

myChar =  pgm_read_byte_near(myArray + k); 


 


 


 


星期三, 3月 04, 2015

使用 re 模組抓出檔名內的數字


    #() 內的值就是會取得的變動值, \d 代表數字, \d+ 表示多個數字
    import re

    patt = re.compile('NO(\d+)TIME(\d+)')
    mobj = patt.match('NO9TIME1')
    print mobj.groups()  # ('9','2')
    print len(mobj.groups())
    print mobj.group(2)  # 1
   
    # mobj.groups() 會列出 mobj 裡的 group 資料
    # len(mobj.groups()) 就可以知道有多少筆了
   
    # 可使用名稱來讀取抓到的資料 ?P
   
    patt = re.compile('NO(?P\d)TIME(?P\d)')
    mobj = patt.match('NO9TIME2')
    print mobj.group('left_num')  # 9
    print mobj.group('time_num') # 2

    # 如果沒有 match , mobj 為 None

python 讀取目錄內檔案名稱

   
    cur_path = os.getcwd() #得知目前路徑
    for subdir, dirs, files in os.walk(cur_path):
        for file in files:
            # 得到檔案名稱 file

python 寫資料到 xls 檔中

使用 xlwt 模組,但 xlwt 不相容於 python 3.x 
xlwt-future 0.8.0 可以支援 python 3.x

最多支援到 256 column 的資料檔案
用法:
    import xlwt
    from xlwt  import Workbook
   
    wb = xlwt.Workbook(encoding='utf-8')         # open workbook
    ws = wb.add_sheet('First Sheet')                 # add sheet
    ws.write(row_num, col_num,'hello world')    # write data to cell
    wb.save('data_file.xls')                                 # write to xls file


python 3.x print 用法

python 3.x 的 print 無法像 python 2.x 一樣的用法:
3.x: print('hello world')
2.x: print 'hello world'

如果不斷行
3.x: print('hello world', end='')  # 使用空白字元, 或是空字元代替
2.x: print 'hello world',             # 使用 , (逗點)