熱門文章
[VB.Net] UI介面多國語系切換功能
UI介面多國語系切換功能 Imports System.ComponentModel Imports System.Globalization Imports System.Resources 'UI介面語系轉換 Public Class C_UILanguage Private systemResourceManager As ResourceManager Private errorResourceManager As ResourceManager Dim CRM As System.ComponentModel.ComponentResourceManager Public Sub New() systemResourceManager = New ResourceManager("專案名稱.Resources", GetType(C_UILanguage).Assembly) errorResourceManager = New ResourceManager("專案名稱.Resources.ErrorMessages", GetType(C_UILanguage).Assembly) End Sub Public Sub _Main(ByVal _Form As Windows.Forms.Form) '檢查引數 If _Form Is Nothing Then _Form.Text = "Form" Throw New ArgumentNullException(_Form.Text) End If CRM = Nothing '切換介面顯示的語言 Try CRM = New ComponentResourceManager(_Form.GetType) ' 設置表單的標題 CRM.ApplyResources(_Form, "$this...
[C#] 使用 ClosedXML將DataGridView 匯出至 Excel
使用 ClosedXML將DataGridView 匯出至 Excel using ClosedXML.Excel; public void ExportToExcel() { var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("Sheet1"); // 匯出 DataGridView 標題 for (int col = 0; col < dataGridView1.Columns.Count; col++) { ws.Cell(1, col + 1).Value = dataGridView1.Columns[col].HeaderText; } // 匯出 DataGridView 內容 for (int row = 0; row < dataGridView1.Rows.Count; row++) { for (int col = 0; col < dataGridView1.Columns.Count; col++) { var cellValue = dataGridView1.Rows[row].Cells[col].Value; ws.Cell(row + 2, col + 1).Value = cellValue != null ? cellValue.ToString() : ""; } } // 儲存 Excel wb.SaveAs(@"C:\Temp\Data.xlsx"); MessageBox.Show("Excel 匯出完成!"); } 參考網址: By Hao★
留言
張貼留言
歡迎留言