發表文章

C# 自訂 XCOPY 類別 :複製資料夾內所有檔案與子資料夾內容到目的資料夾(並覆蓋)

圖片
Xopy.class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Tools {     public class Xcopy     {         private string _message;         /// <summary>         /// 錯誤訊息         /// </summary>         public string Message         {             get { return _message; }         }         /// <summary>         /// 複製檔案群         /// </summary>         /// <param name="_source">來源資料夾</param>         /// <param name="_target">目的資料夾</param>         /// <param name="recursive">包含子資料夾</param>         /// <returns>成功 = 1 , 失敗 = -1</returns>         public int Copy(string _source, string _target, bool recursive = true)         {             try             {                 if (!Directory.Exists(_source))                 {                     _message = "來源資料夾不存在!";                     return

LaunchMan : start and check version and update 自訂啟動更新程式

圖片
  說明: 這支程式的用途就是和你的程式擺在一起,然後將這支程式設定成你的程式啟動用。 這支程式啟動時,會依照 INI檔的設定去幫你檢查程式版本。 如果有版本異動時,會提醒使用者要更新程式。 支援: 支援HTTP和FTP協定,可以依照你的需求把更新檔案放在WEB server或是FTP server上 環境: 僅能運行在Windows 下 由 dotNet 4.5 開發,需要作業系統支援 dotNet 4.5 的程式執行, 如果沒有,可以 下載安裝 dotNet FrameWork 4.5 套件 。 下載: LaunchMan 範例: 我有一個 kiosk 程式 main.exe 放在  C:\APP\KioskPatch 桌面上有個程式捷徑連結到 C:\APP\KioskPatch\main.exe 現在,我們把 LaunchMan 程式和這個 Kiosk 程式放在一起 (不放一起其實也可以,這樣比較好管) 修改桌面捷徑改連結到 C:\APP\KioskPatch\LaunchMan.exe 而更新檔案 有兩個 一個是 version.txt , 另一個為壓縮檔( 例如KioskPatch.ZIP ) 都放在我的網站 www.mycomp.com.tw/Patch/down/ 下 然後在 C:\APP\KioskPatch 下也放一個 version.txt 這兩個 version.txt 內容要不一樣,當內容不同時,才會啟動更新 然後,修改 INI 檔案(範例在下方) [Application] ;使用的背景圖片,自訂圖片,該圖片必須有DPI資訊才能正常顯示 LogoPicture=splash2.png ;淡入效果時間 ;Second unit FadeINDuration=3 FadeOutDuration=1 ;讓背景透明 BackgroundTransparency=true ;顯示訊息文字顏色/位置 MessageTextColor=#0000FF MessageLeftPosition=10 messageTopPosition=130 Title="Kiosk Sell System with .Net" TitleTextColor=#FF0000 TitleLeftPosition=50

C# csv 檔匯入 List 一行搞定

圖片
  我有一個CSV 檔案(data.csv),內容大約如下: 編號,姓名,性別 T001,林黃頻,男 T002,江國勘,男 T003,劉簿相,男 所以,依照欄位我會定義出一個儲存用類別(Field.cs): namespace MyApp {     class Field     {         public Field(string Line)         {             var sp = Line.Split(',');             UserNo = sp[0];             UserName = sp[1];             Gender = sp[2];         }         public string UserNo { get; set; }         public string UserName { get; set; }         public string Gender { get; set; }                 public override string ToString()         {             string output =  UserNo+ "\t" + UserName + "\t" + Gender + "\r\n";             return output;         }     } } 主要程式碼其實只要一行就可以搞定(不含using) using System.IO ‧ ‧ ‧ // 這一行讀入CSV併排除第一行標題 List<Field> content = File.ReadAllLines("D:\\data.csv", Encoding.Default).Select(line => new Data1(line)).Skip(1).ToList(); // 顯示出來 foreach(Data1 item in totl) {      textBox1.Text += item.ToString(); } ‧ ‧ ‧

頒獎用程式【分享】

圖片
  頒獎用顯示程式(含原始碼 pbw) 開發工具:Powerbuilder 10.5 版本:2.0.2.6 版本時間:2019/3/5 平台:Windows 下載位置: https://drive.google.com/file/d/1XX8SDzyeHaZxvOAlmmPOmWu4JJP1dkEp/view?usp=sharing 程式說明: 因應公司於大型會場需要頒獎時,能將得獎者名單顯示在會場投射螢幕上,由於公司參加者眾多超過300人,部分獎項得獎者可能多達50人以上,若主持人連續抽出得獎者並說出得獎者名字或編號時,現場吵雜情況下,得獎者會不知道自己已經得獎,因此透過投射螢幕可以把得獎者清單列於畫面上,讓得獎者不會錯過。

EXCEL Convert to CSV File Tool

Tool Name:  EXCEL2CSV.exe Verson: 1.0.0.0 Development Environment: MS-Visual Studio 2017 FrameWork: .Net 3.5 Description: this is a console tool to convert Excel files (eg: xls , xlsx , csv) to a uniform comma separated format data file (.CSV) without quotes between each field. if excel cell data include Enter/TAB characters or double will be replace by empty. if excel cell data include comma character , it will be replace by dot . this tool is third party for data process application (eg: EDI)to import pure data. this tool package include donet FrameWork 3.5 installer. OS: Windows XP/Windows 7/Windows 8/Windows 10 download: there usage: excel2csv.exe [full source filename] [full destination file name] if source file name or destination file name not with full path , it will use caller environment path locate. if destination file failed to create is an error on convert duration. full source file name or full destination file name need warp by double-Quotes if it include space. example:

使用 NPOI 設定欄位(CELL)樣式與寬度

圖片
如何使用 NPOI 來設定CELL(欄位)的樣式:邊框、底色、字形,等等 底下是個 樣式類別檔案,把常用的欄位形態定義好,以後直接取用 DefXSSFstyle.cs using System.Drawing; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.HSSF.Util; namespace XssSTYLE {     /// <summary>     /// 已經定義好的欄位樣式,如果需要新樣式,複製程式碼並賦與新名稱,修改樣式產生程式碼即可使用     /// </summary>     class DefXSSFstyle     {         /// <summary>         /// 抬頭樣式 - 01         /// 灰色底色,白色字,正黑體,無邊框         /// </summary>         /// <param name="wb"></param>         /// <returns></returns>         public XSSFCellStyle Banner01(IWorkbook wb)         {             XSSFCellStyle csh = (XSSFCellStyle)wb.CreateCellStyle();             csh.Alignment = HorizontalAlignment.Center;             csh.VerticalAlignment = VerticalAlignment.Center;             csh.WrapText = true;             csh.FillForegroundXSSFColor = new XSSFColor(Color.FromKnownColor(KnownColor.Gray));             csh.FillPattern = FillPattern.SolidForeground;             IFont f

關於 NPOI 取得 列 (Row) 和 欄(Cell) 數量

圖片
關於 NPOI 裏面如何取得 列(Row) 與欄(Cell)的數量。 NPOI 對於 IRow 或 ICell 沒有類似集合數量的 count 或是 length 可以取得, 可是相對的有 FirstRowNum / LastRowNum / FirstCellNum / LastCellNum 可以用。 它代表是 首列位置 / 末列位置 / 首欄位置 / 末欄位置 但是非常奇異的是,這兩種的取出值卻完全不是這麼一回事 正常來說,以位置來看的話, C# 計算是從 0 開始 因此以上圖 EXCEL來看應該是: FirstRowNum = 0 LastRowNum = 10 FirstCellNum  = 0 LastCellNum  = 10 列(Row) 和 欄(Cell) 和都 各11個 但是,我們實際把它取出來看卻發現詭異事情了 Console.WriteLine("FirstRowNum = " + ws1.FirstRowNum.ToString() + " ,LastRowNum = " + ws1.LastRowNum.ToString()); Console.WriteLine("FirstCellNum = " + ws1.GetRow(0).FirstCellNum.ToString() + " ,LastCellNum = " + ws1.GetRow(0).LastCellNum.ToString()); 結果: 看! LastCellNum 居然是 11  NPOI 有太多小問題真的很想吐槽了 這個問題 去年被發現 ,但是至今尚未改善 如要參照這個屬性一定要非常小心,哪天突然修正好,你的程式可能也要跟著更新與修正了。