2017年1月8日 星期日

[How To Arduino] MTARDMAX7219 自製圖型


腳位定義:
  1.  VCC   => 5V
  2.  GND
  3.  DIN    => Pin 12
  4.  CS      => Pin 10
  5.  CLK   => Pin 11


#include "LedControl.h"

LedControl lc=LedControl(12,11,10,2);  // Pins: DIN,CLK,CS, # of Display connected

unsigned long delayTime=200;  // Delay between Frames

// Put values in arrays
byte invader1a[] =
{
   B00011000,  // First frame of invader #1
   B00111100,
   B01111110,
   B11011011,
   B11111111,
   B00100100,
   B01011010,
   B10100101
};

byte invader1b[] =
{
  B00011000, // Second frame of invader #1
  B00111100,
  B01111110,
  B11011011,
  B11111111,
  B00100100,
  B01011010,
  B01000010
};

void setup()
{
  lc.shutdown(0,false);  // Wake up displays
  lc.shutdown(1,false);
  lc.setIntensity(0,5);  // Set intensity levels
  lc.setIntensity(1,5);
  lc.clearDisplay(0);  // Clear Displays
  lc.clearDisplay(1);
}


//  Take values in Arrays and Display them
void sinvader1a()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0,i,invader1a[i]);
  }
}

void sinvader1b()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0,i,invader1b[i]);
  }
}

void loop()
{
// Put #1 frame on both Display
    sinvader1a();
    delay(delayTime);


// Put #2 frame on both Display
    sinvader1b();
    delay(delayTime);

}



參考出處:
https://brainy-bits.com/tutorials/how-to-control-max7219-led-matrix/

[How To Arduino] KTDUINO MAX7219 8X8點矩陣驅動控制模組/ MTARDMAX7219





模組測試

腳位定義:
  1.  VCC   => 5V
  2.  GND
  3.  DIN    => Pin 12
  4.  CS      => Pin 10
  5.  CLK   => Pin 11

Arduino 官方網站 - LedControl
http://playground.arduino.cc/Main/LedControl


LedControl 函式庫下載
https://github.com/wayoda/LedControl


請函式庫解壓縮放至以下路徑:(依安裝路徑而不同)
C:\Program Files (x86)\Arduino\libraries 



#include "LedControl.h" //  need the library
LedControl lc=LedControl(12,11,10,1); //

// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 1 as we are only using 1 MAX7219

void setup()
{
  // the zero refers to the MAX7219 number, it is zero for 1 chip
  lc.shutdown(0,false);// turn off power saving, enables display
  lc.setIntensity(0,8);// sets brightness (0~15 possible values)
  lc.clearDisplay(0);// clear screen
}
void loop()
{
  for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,true); // turns on LED at col, row
      delay(25);
    }
  }

  for (int row=0; row<8; row++)
  {
    for (int col=0; col<8; col++)
    {
      lc.setLed(0,col,row,false); // turns off LED at col, row
      delay(25);
    }
  }
}




參考出處:
http://tronixstuff.com/2013/10/11/tutorial-arduino-max7219-led-display-driver-ic/

2016年12月21日 星期三

C 語言 字串反轉


#include <stdio.h>

void main(void)
{
    //字元陣列不用宣告大小, 結束字元必需加上 \0
    char str[] = {'A', 'B', 'C', 'D', 'E', 'F', '\0'};
    char temp[1];                   // 暫存字串

    int str_length = sizeof(str)-1; // 字元長度減去結束字元, 長度為6
    int count;

    for(count=0; count<(str_length/2); count++)
    {
        temp[0] = str[count];
        str[count] = str[str_length-1-count];
        str[str_length-1-count] = temp[0];
    }

    printf("Reverse:(%s)\n", str);
}

C 語言變數



韌體工程師 考題

  1. 何謂 全域變數 (Global Variable)
  2. 何謂 區域變數 (Local Variable)
  3. 何謂 靜態變數 (Static Variable)

/*
自動儲存區間與靜態儲存區間
*/

#include  <stdio.h>

int    fx = 0;                          /* 靜態儲存區間+檔案有效範圍 */

void func(void)
{
     static int       sx = 0;           /* 靜態儲存區間+資料段有效範圍 */
     int              ax = 0;           /* 自動儲存區間+資料段有效範圍 */


     printf("%3d%3d%3d\n", ax++, sx++, fx++);
}

int main(void)
{
    int    i;

    puts(" ax sx fx");
    puts("----------");
    for (i = 0; i < 10; i++)
        func();
    puts("----------");
 
    return (0);
}



參考出處:
明解C語言


關鍵字:
omgiraaaaonpo
pirhdln
ogetptd
otgistv

2016年10月3日 星期一

[C#] 建立 Log 檔


log4net 套件網址:
http://logging.apache.org/log4net/download_log4net.cgi

log4net 套件名稱:
log4net-1.2.15-bin-newkey

log4net 套件檔案路徑:
log4net-1.2.15\bin\cli\1.0\release



  • 將 log4net.dll 加入到專案目錄下 (記得專案要指定參考此連結檔)
  • 在 assemblyinfo.cs 設定檔中加入
[assembly: log4net.Config.XmlConfigurator(ConfigFile="Log4Net.config", Watch=true)]
  • 複製 Log4Net.config 至專案中

程式碼:
using log4net;  

namespace Log4netExample
{
    public partial class Form1 : Form
    {
        private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);  

        public Form1()
        {
            InitializeComponent();

            log.Debug("Hello Log");
        }
    }
}

注意:

 Log4Net.config 檔案屬性 => 複製到輸出目錄 需設定成 "有更新時才複製"



產生的 Log 會在專案目錄下的
Log4netExamplenetExa\bin\Debug\applicationLog



Log4net 套件檔案:

Log4Net.config 檔案:

範例檔案:

2016年9月28日 星期三

[C/C++] Notepad++ 套件SourceCookifier (似source insight)


參考如下:

NotePad++中SourceCookifier插件的使用
http://fanli7.net/a/bianchengyuyan/C__/20130915/424309.html


相關參考:
notepad++ ctag

[C/C++] 使用 Visual Studio 編譯 C語言


#include <stdio.h>

void main()
{
int a = 10;
int *p = &a; //創建一個變量p容維a的地址
printf("%x", p);//印出地址

*p=5; //根據地址取出內容, 對內容賦值, *p等價於a

printf("%d,%d", *p, a);
getchar();
}

參考出處:
https://www.youtube.com/watch?v=vEhLwsuif7E&app=desktop

程式檔案:
https://drive.google.com/open?id=0B-oSnsmCU0yMV3ZiX1pBbkVmWU0

[C#] MySQL 四大功能 (新增、刪除、更新、搜尋)


//載入MySQL元件
using MySql.Data;
using MySql.Data.MySqlClient;

namespace ConnectMySQL
{
    public partial class Form1 : Form
    {
        string dbHost = "127.0.0.1";    //資料庫位址
        string dbUser = "root";         //資料庫使用者帳號
        string dbPass = "xxxx";     //資料庫使用者密碼
        string dbName = "TestDB";       //資料庫名稱

        public Form1()
        {
            InitializeComponent();

            MySQL_Select();
        }

        /// <summary>
        /// 測試連結資料庫
        /// </summary>
        private void TestConnect()
        {
            // 如果有特殊的編碼在database後面請加上;CharSet=編碼, utf8請使用utf8_general_ci
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);

            //MySQLCommand commn = new MySQLCommand("set names big5", conn);

            // 連線到資料庫
            try
            {
                conn.Open();
                MessageBox.Show("mysql 連線成功");
            }
            catch
            {
                MessageBox.Show("mysql 連線失敗");
            }
        }

     
        /// <summary>
        /// 新增資料
        /// </summary>
        private void MySQL_Insert()
        {
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            String account;
            String password;
            int level;
            for (int i = 0; i < 10; i++)
            {
                account = "account" + i.ToString();
                password = "password" + i.ToString();
                level = i * 10;
                command.CommandText = "Insert into member(account,password,level) values('" + account + "','" + password + "'," + level + ")";
                command.ExecuteNonQuery();
            }
            Console.ReadLine();
            conn.Close();
        }

        /// <summary>
        /// 刪除資料
        /// </summary>
        private void MySQL_Delete()
        {
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            command.CommandText = "Delete FROM member WHERE id=5";
            int n = command.ExecuteNonQuery();

            Console.WriteLine("共刪除 {0} 筆資料", n);
            Console.ReadLine();
            conn.Close();
        }

        /// <summary>
        /// 更新資料
        /// </summary>
        private void MySQL_Update()
        {
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            command.CommandText = "Update member SET password='1234' WHERE account='account6'";
            command.ExecuteNonQuery();

            Console.ReadLine();
            conn.Close();

        }


        string[] row1 = new string[4];
        object[] rows = new object[] { };

        /// <summary>
        /// 搜尋資料
        /// </summary>
        private void MySQL_Select()
        {
            string connStr = "server=" + dbHost + ";uid=" + dbUser + ";pwd=" + dbPass + ";database=" + dbName;
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand command = conn.CreateCommand();
            conn.Open();

            String cmdText = "SELECT * FROM member WHERE level <= 90";
            MySqlCommand cmd = new MySqlCommand(cmdText, conn);
            MySqlDataReader reader = cmd.ExecuteReader(); //execure the reader

            while (reader.Read())
            {
                for (int i = 0; i < 4; i++)
                {
                    String s = reader.GetString(i);

                    switch (i)
                    {
                        case 0:
                            row1[0] = reader.GetString(i);
                            break;
                        case 1:
                            row1[1] = reader.GetString(i);
                            break;
                        case 2:
                            row1[2] = reader.GetString(i);
                            break;
                        case 3:
                            row1[3] = reader.GetString(i);
                            break;
                        default:
                            break;
                    }

                    rows = new object[] { row1 };
                }

                foreach (string[] rowArray in rows)
                {
                    dataGridView1.Rows.Add(rowArray);
                }

                Console.Write("\n");
            }

            Console.ReadLine();
            conn.Close();
        }

    }
}

參考出處:
http://roboardgod.blogspot.tw/2013/08/cmysql.html

程式檔案:
https://drive.google.com/open?id=0B-oSnsmCU0yMUDZ1c2xLOThSeWs

2016年9月16日 星期五

[C#] MySQL 運用


MySQL  Connector/Net 6.2.5
Link



C# 專案 -> 參考(右鍵) -> 加入參考 -> 載入MySQL元件
using MySql.Data;
using MySql.Data.MySqlClient;




MySQL 匯出資料庫:



參考資料庫:
Link


參考出處:
[更新] C#連接MySQL
[教學] 如何使用C#存取MySQL資料庫


2016年9月13日 星期二

[C#] DataTable 使用select搜尋並修改欄位

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//載入DataTable
using System.Data;

namespace DataTable_Select
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a table of five different people.
            // ... Store their size and sex.
            DataTable table = new DataTable("School");
            table.Columns.Add(new DataColumn("Number", typeof(int)));
            table.Columns.Add(new DataColumn("Name", typeof(string)));

            table.Rows.Add(1, "Kevin");
            table.Rows.Add(2, "Justin");
            table.Rows.Add(3, "Chris");
            table.Rows.Add(4, "Fiona");
            table.Rows.Add(5, "John");

            // Search for people above a certain size.
            // ... Require certain sex.
            DataRow[] result = table.Select("Name = 'Fiona'");

            //修改前
            //DataTable table = GetTable(); // 取得資料表
            foreach (DataRow row in table.Rows) // 讀取行
            {
                Console.WriteLine("--- Row ---"); // Print separator.
                foreach (var item in row.ItemArray) // 讀取每個項目
                {
                    Console.Write("Item: "); // Print label.
                    Console.WriteLine(item); // Invokes ToString abstract method.
                }
            }

            //修改中
            for (int i = 0; i < result.Length; i++)
            {
                Console.WriteLine(result[i][0] + "\t" + result[i][1]);
                Console.WriteLine("取得搜尋的行號:"+i);
                result[i][1] = "May";
            }

            //修改後
            //DataTable table = GetTable(); // 取得資料表
            foreach (DataRow row in table.Rows) // 讀取行
            {
                Console.WriteLine("--- Row ---"); // Print separator.
                foreach (var item in row.ItemArray) // 讀取每個項目
                {
                    Console.Write("Item: "); // Print label.
                    Console.WriteLine(item); // Invokes ToString abstract method.
                }
            }

            Console.ReadLine();
        }
    }
}



程式檔案:

[C#] 讀寫XML 並結合 DataTable


目的是設計XML格式並利用 DataTable, 寫入檔案 Default_Setting.xml

再讀取XML格式, 重新寫入 DataTable















using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//DataTable 載入
using System.Data;
//XElement 載入
using System.Xml.Linq;
//讀取專案路徑
using System.Windows;
//XElement 載入
using System.Xml;

//using System.Data;

namespace XML_Example
{
    class Program
    {
        //讀取專案路徑
        static string ProjectPath = System.Environment.CurrentDirectory + "\\Default_Setting.xml";

        //建立新資料表
        static DataTable SourceDT = new DataTable("SourceDT");

        //讀取XML寫入資料表
        static DataTable NewDT = new DataTable("SourceDT");
     

        private static void Main(string[] args)
        {
            DataTableCreate();
            XMLCreate();
            ReadXML();
            Console.ReadLine();
        }

        /// <summary>
        /// 建立資料表提供XML儲存使用
        /// </summary>
        private static void DataTableCreate()
        {
         
            //建立資料格式
            SourceDT.Columns.Add("Name", typeof(string));
            SourceDT.Columns.Add("Chinese", typeof(string));
            SourceDT.Columns.Add("English", typeof(string));

            //新增資料
            //格式: 姓名 -> 國文成績 -> 英文成績 -> 數學成績
            SourceDT.Rows.Add("Kevin", "male", "ordinary");
            SourceDT.Rows.Add("Justin", "Female", "excellent");

            Console.WriteLine("原始DataTable資料");

            //DataTable table = GetTable(); // 取得資料表
            foreach (DataRow row in SourceDT.Rows) // 讀取行
            {
                Console.WriteLine("--- Row ---"); // Print separator.
                foreach (var item in row.ItemArray) // 讀取每個項目
                {
                    Console.Write("Item: "); // Print label.
                    Console.WriteLine(item); // Invokes ToString abstract method.
                }
            }
        }

        /// <summary>
        /// 利用datatable轉換為XML檔案
        /// </summary>
        private static void XMLCreate()
        {
            XElement Layer1 = new XElement("application");

            XElement Layer2 = new XElement("myClass");

            Layer2.Add(new XAttribute("Name", "Sheep"));
            Layer2.Add(new XElement("ClassRoom", "A-301"));

            foreach (DataRow row in SourceDT.Rows) // 讀取行
            {
                XElement Layer3 = new XElement("ClassMate");

                Layer3.Add(new XAttribute("Name", row[0].ToString()));
                Layer3.Add(new XElement("Gender", row[1].ToString()));
                Layer3.Add(new XElement("Score", row[2].ToString()));
                Layer2.Add(Layer3);
            }

            Layer1.Add(Layer2);

            XDocument xdoc = new XDocument();
            xdoc.Add(Layer1);
            xdoc.Save(ProjectPath);
        }

     

        private static void ReadXML()
        {
            //建立資料格式
            NewDT.Columns.Add("Name", typeof(string));
            NewDT.Columns.Add("Chinese", typeof(string));
            NewDT.Columns.Add("English", typeof(string));


            var allClassMates = XDocument.Load(ProjectPath).Root.Element("myClass").Elements("ClassMate");



            foreach (var person in allClassMates)
            {
                string name = person.Attribute("Name").Value;   // 屬性
                string gender = person.Element("Gender").Value;  // InnerText
                string score = person.Element("Score").Value;    // InnerText

                NewDT.Rows.Add(name, gender, score);
            }

            Console.WriteLine("\nXML讀取寫入DataTable");

            //DataTable table = GetTable(); // 取得資料表
            foreach (DataRow row in NewDT.Rows) // 讀取行
            {
                Console.WriteLine("--- Row ---"); // Print separator.
                foreach (var item in row.ItemArray) // 讀取每個項目
                {
                    Console.Write("Item: "); // Print label.
                    Console.WriteLine(item); // Invokes ToString abstract method.
                }
            }
        }
    }
}


XML檔案路徑:
[專案下]\XML_Example\XML_Example\bin\Debug\Default_Setting.xml


程式檔案:
Link

參考出處:
[C# 3.0] XLinq (Linq for XML Data)
[C#]Linq to XML 讀取XML檔


[C#] MySQL 安裝


MySQL 官方網站下載:
Link


安裝教學可以參考以下二篇:
Windows上的MySQL安裝教學 (使用MySQL Installer)
[研究] MySQL 5.7 安裝 (mysql-installer-community-5.7.9.0.msi) Developer

























2016年9月7日 星期三

[STM32F4] STM32F429I-DISC1 LCD 開發板介紹



意法半導體(ST) - 官方網站



開發平台:
  1. Windows Series
  2. Linux (Ubuntu)
  3. MAC OS

開發工具:
  1. Altium:TASKING™VX-Toolset
  2. Atollic:TrueSTUDIO
  3. IAR:EWARM
  4. Keil™:MDK-ARM

      系統架構:










      參考網站:

      何謂 mbed - Link

      [STM32F4] STM32F429I-DISC1 LCD 開發板介紹



      意法半導體(ST) - 官方網站


      開發平台:
      1. Windows Series
      2. Linux (Ubuntu)
      3. MAC OS

      開發工具:
      1. Altium:TASKING™VX-Toolset
      2. Atollic:TrueSTUDIO
      3. IAR:EWARM
      4. Keil™:MDK-ARM

          系統架構:










          參考網站:

          何謂 mbed - Link

          2016年9月4日 星期日

          [C#] Windows Form 元件搜尋



          C# 主要元件如下圖, 如果需要找尋元件名稱或是標籤名稱可以透過以下程式方法


          namespace WindowsFormsApplication2
          {
              public partial class Form1 : Form
              {
                  public Form1()
                  {
                      InitializeComponent();

                      //第一層的 WinForm 的所有元件
                      foreach (Control Layer1 in this.Controls)
                      {
                          //過濾第二層的 TabControl
                          if (Layer1.GetType().Name == "TabControl")
                          {
                              //第二層的 TabControl 的所有元件
                              foreach (Control Layer2 in Layer1.Controls)
                              {
                                  //過濾第三層的 TabPage
                                  if (Layer2.GetType().Name == "TabPage")
                                  {
                                      //第三層的 TabPage 的所有元件
                                      foreach (Control Layer3 in Layer2.Controls)
                                      {
                                          //過濾第四層的 TableLayoutPanel
                                          if (Layer3.GetType().Name == "TableLayoutPanel")
                                          {
                                              //第四層的 TableLayoutPanel 的所有元件
                                              foreach (Control Layer4 in Layer3.Controls)
                                              {
                                                  Console.WriteLine(Layer4.GetType().Name);
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }

          程式檔案:
          Link

          [C#] Windows Form 元件搜尋



          C# 主要元件如下圖, 如果需要找尋元件名稱或是標籤名稱可以透過以下程式方法


          namespace WindowsFormsApplication2
          {
              public partial class Form1 : Form
              {
                  public Form1()
                  {
                      InitializeComponent();

                      //第一層的 WinForm 的所有元件
                      foreach (Control Layer1 in this.Controls)
                      {
                          //過濾第二層的 TabControl
                          if (Layer1.GetType().Name == "TabControl")
                          {
                              //第二層的 TabControl 的所有元件
                              foreach (Control Layer2 in Layer1.Controls)
                              {
                                  //過濾第三層的 TabPage
                                  if (Layer2.GetType().Name == "TabPage")
                                  {
                                      //第三層的 TabPage 的所有元件
                                      foreach (Control Layer3 in Layer2.Controls)
                                      {
                                          //過濾第四層的 TableLayoutPanel
                                          if (Layer3.GetType().Name == "TableLayoutPanel")
                                          {
                                              //第四層的 TableLayoutPanel 的所有元件
                                              foreach (Control Layer4 in Layer3.Controls)
                                              {
                                                  Console.WriteLine(Layer4.GetType().Name);
                                              }
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }

          程式檔案:
          Link

          2016年7月20日 星期三

          [C#] 使用 Windows API 讀取 ini 設定檔


          專案路徑下新增專案內的
          \bin\Debug
          裡面新增設定檔 myConfig.ini


          using System.Runtime.InteropServices;
          using System.IO;

          namespace WindowsFormsApplication1
          {
              public partial class Form1 : Form
              {

                  [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
                  private static extern bool WritePrivateProfileString(string sectionName, string keyName, string keyValue, string filePath);

                  [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
                  private static extern int GetPrivateProfileString(string sectionName, string keyName, string defaultReturnString, StringBuilder returnString, int returnStringLength, string filePath);


                  public Form1()
                  {
                      InitializeComponent();

                      //取得應用程式的可執行檔路徑,不包括檔名,通常都是位於Debug資料夾
                      string Rundir = Application.StartupPath + "\\myConfig.ini";

                      //建立ini檔案
                      WritePrivateProfileString("Owner", "name", "Dan Mac", @"D:\Temp\myConfig.ini");
                      WritePrivateProfileString("Owner", "organization", "Apple Inc.", @"D:\Temp\myConfig.ini");
                      WritePrivateProfileString("Database", "server", "192.168.1.100", @"D:\Temp\myConfig.ini");
                      WritePrivateProfileString("Database", "port", "50000", @"D:\Temp\myConfig.ini");
                      WritePrivateProfileString("Database", "file", "\"db.dat\"", @"D:\Temp\myConfig.ini");


                      //讀取ini檔案
                      StringBuilder data = new StringBuilder(255);
                      GetPrivateProfileString("Database", "file", "NA", data, 255, Rundir);
                      Console.WriteLine(data);

                  }

              }

          }

          參考出處:
          http://einboch.pixnet.net/blog/post/250128728
          http://blog.yam.com/phone875/article/25773797

          2016年7月17日 星期日

          [C#] 新增 Excel 表並寫入測試資料


          目前研究C#讀寫取 Excel

          解析方式有以下三種:OleDb、Com組件、NPOI


          先載入參考

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using System.IO;
          using Excel = Microsoft.Office.Interop.Excel;



          namespace ReadExcel
          {
              public partial class Form1 : Form
              {
                  public Form1()
                  {
                      InitializeComponent();


                      FileInfo fi = new FileInfo("Data.xls");
                      Microsoft.Office.Interop.Excel.Application xlapp = new Microsoft.Office.Interop.Excel.Application();
                      if (xlapp == null)
                      {
                          MessageBox.Show("請安裝office!!");
                      }
                      xlapp.Visible = false;//不顯示excel程式
                      Workbook wb = xlapp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
                      Worksheet ws = (Worksheet)wb.Sheets[1];
                      ws.Name = "English";
                      Worksheet ws1 = (Worksheet)wb.Worksheets.Add(Type.Missing, ws, Type.Missing, Type.Missing);//建立一個新分頁
                      ws1.Name = "Japanese";
                      ws.Cells[1, 1] = "word";
                      ws.Cells[1, 2] = "translate";
                      ws1.Cells[1, 1] = "word";
                      ws1.Cells[1, 2] = "translate";
                      ws.Cells[2, 1] = "Hello";
                      ws.Cells[2, 2] = "哈囉";
                      ws1.Cells[2, 1] = "こんにちは";
                      ws1.Cells[2, 2] = "你好";
                      if (ws == null || ws1 == null)
                      {
                          MessageBox.Show("建立sheet失敗");
                      }
                      wb.SaveAs(@fi.DirectoryName + "\\Data.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel8, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                      wb.Close(false, Type.Missing, Type.Missing);
                      xlapp.Workbooks.Close();
                      xlapp.Quit();
                      //刪除 Windows工作管理員中的Excel.exe process,
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(wb);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
                  }
              }
          }