// 做檔案轉換
 private void Button_Translate_Click(object sender, EventArgs e)
 {
     if (m_listFilename.Count == 0)
     {
         MessageBox.Show("請拖檔案進來處理");
         return;
     }
     // 檔案一個一個處理
     foreach (string strFilename in m_listFilename)
     {
         Dictionary <string, SingleExcelEx> dictExcel = ExcelExMgr.instance().GetExcelSheet(strFilename);
         List <string> listSheetName = new List <string>(dictExcel.Keys);
         foreach (string SheetName in listSheetName)
         {
             SingleExcelEx Single = dictExcel[SheetName];
             // 做存檔的動作 - Server
             Single.SaveToJson("../Login/GameData/");
             // 做存檔的動作 - Client
             Single.SaveToJson("../../SanguoClient/Assets/JsonTxt/");
         }
     }
     MessageBox.Show("轉換成功");
 }
Beispiel #2
0
//	public void Save(bool IsUseBackup=true)
    public void Save()
    {
        if (m_dictProperty.Count == 0)
        {
            return;
        }
        // 重新再做一次載入
        ExcelExMgr.instance().ReloadAll();
        using (FileStream fs = new FileStream(m_ExcelName, FileMode.Open))
        {
            IWorkbook WorkBook = new HSSFWorkbook(fs);
            fs.Close();
            ISheet Sheet = WorkBook.GetSheet(m_SheetName);
            // 把資料寫回去
            for (int RowIndex = 0; RowIndex < m_listKey.Count; RowIndex++)
            {
                int    RealRowIndex = RowIndex + 3;
                string strKey       = m_listKey[RowIndex];
                IRow   Row          = Sheet.GetRow(RealRowIndex);
                if (Row == null)
                {
                    Row = Sheet.CreateRow(RealRowIndex);
                }
                for (int ColumnIndex = 0; ColumnIndex < m_listColumn.Count; ColumnIndex++)
                {
                    string strColumn  = m_listColumn[ColumnIndex];
                    string strKeyWord = GetKeyWord(strKey, strColumn);
                    // 如果沒有相關資料也不需要變更
                    if (m_dictProperty.ContainsKey(strKeyWord) == false)
                    {
                        continue;
                    }
                    // 如果是空的就先產生
                    ICell Cell = Row.GetCell(ColumnIndex);
                    if (Cell == null)
                    {
                        Cell = Row.CreateCell(ColumnIndex);
                    }
                    // 設定數值
                    string strValue = m_dictData[strKey][strColumn].ToString();
                    // 數字
                    if (Utility.IsDigit(strValue) == true)
                    {
                        Row.GetCell(ColumnIndex).SetCellValue(System.Convert.ToInt32(strValue));
                    }
                    // 浮點數
                    else if (Utility.IsFloat(strValue) == true)
                    {
                        Row.GetCell(ColumnIndex).SetCellValue(System.Convert.ToDouble(strValue));
                    }
                    //// 浮點數
                    //else if (Utility.IsPercentFloat(strValue) == true)
                    //{
                    //    Row.GetCell(ColumnIndex).SetCellValue(System.Convert.ToDouble(strValue));
                    //}
                    else
                    {
                        Row.GetCell(ColumnIndex).SetCellValue(strValue);
                    }
                    // 設定屬性
                    SetPerpertyToExcel(strKey, strColumn, Cell, WorkBook);
                }
            }
            string strOutName = m_ExcelName;
#if BACK_UP
            strOutName += ".auto.xls";
#endif
            FileStream file = new FileStream(strOutName, FileMode.Create);            //產生檔案
            WorkBook.Write(file);
            file.Close();
            // 清除
            WorkBook = null;
            Sheet    = null;
        }
        // 清除掉屬性設定
        m_dictProperty.Clear();
    }