diff --git a/DataCombine/App.config b/DataCombine/App.config new file mode 100644 index 0000000000000000000000000000000000000000..40c8c196b339366361ed359bb8376c438bd133ea --- /dev/null +++ b/DataCombine/App.config @@ -0,0 +1,21 @@ + + + + +
+ + + + + + + + + + + + False + + + + \ No newline at end of file diff --git a/DataCombine/DataCombine.csproj b/DataCombine/DataCombine.csproj new file mode 100644 index 0000000000000000000000000000000000000000..ec4377b256e9cbca5967f2cc4ceb8572d0c26129 --- /dev/null +++ b/DataCombine/DataCombine.csproj @@ -0,0 +1,135 @@ + + + + + Debug + AnyCPU + {7F22DE22-1A7D-4817-8A66-38179A5828C4} + WinExe + DataCombine + DataCombine + v4.5 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\MakeReport\packages\Portable.BouncyCastle.1.8.6\lib\net40\BouncyCastle.Crypto.dll + + + ..\MakeReport\packages\SharpZipLib.1.2.0\lib\net45\ICSharpCode.SharpZipLib.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OOXML.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OpenXml4Net.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OpenXmlFormats.dll + + + + + + + + + + + + + + + + + ..\MakeReport\packages\WpfMessageBox.1.2.0\lib\net40-client\WpfMessageBox.dll + + + + + Form + + + DataCombineMainForm.cs + + + + Form + + + Form_Chart.cs + + + Form + + + Form_SelectYearMonth.cs + + + Form + + + Form_SheetSelect.cs + + + + + DataCombineMainForm.cs + + + Form_Chart.cs + + + Form_SelectYearMonth.cs + + + Form_SheetSelect.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/DataCombine/DataCombineMainForm.Designer.cs b/DataCombine/DataCombineMainForm.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..9181e5f9d9ab2040ccd8599741dd038c405e863e --- /dev/null +++ b/DataCombine/DataCombineMainForm.Designer.cs @@ -0,0 +1,456 @@ +namespace DataCombine +{ + partial class DataCombineMainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataCombineMainForm)); + this.button_Chart_Month = new System.Windows.Forms.Button(); + this.button_Chart_Week = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.ToolStripMenuItem_load_test_data = new System.Windows.Forms.ToolStripMenuItem(); + this.选项ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.打开ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.帮助ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.Column_Count_DGV3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.button3 = new System.Windows.Forms.Button(); + this.Column_Mont = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.button_Month_Combine = new System.Windows.Forms.Button(); + this.button_Week_Combine = new System.Windows.Forms.Button(); + this.Column_Count_DGV2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column_Week = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridView2 = new System.Windows.Forms.DataGridView(); + this.Column_Count_DGV1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column_Date = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridView3 = new System.Windows.Forms.DataGridView(); + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton(); + this.button_Chart_Year = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button_Year_Combine = new System.Windows.Forms.Button(); + this.dataGridView4 = new System.Windows.Forms.DataGridView(); + this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.ToolStripMenuItem_PrintInternalData = new System.Windows.Forms.ToolStripMenuItem(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.statusStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).BeginInit(); + this.SuspendLayout(); + // + // button_Chart_Month + // + this.button_Chart_Month.Location = new System.Drawing.Point(702, 441); + this.button_Chart_Month.Name = "button_Chart_Month"; + this.button_Chart_Month.Size = new System.Drawing.Size(75, 23); + this.button_Chart_Month.TabIndex = 19; + this.button_Chart_Month.Text = "生成图表"; + this.button_Chart_Month.UseVisualStyleBackColor = true; + this.button_Chart_Month.Click += new System.EventHandler(this.button_Chart_Month_Click); + // + // button_Chart_Week + // + this.button_Chart_Week.Location = new System.Drawing.Point(443, 441); + this.button_Chart_Week.Name = "button_Chart_Week"; + this.button_Chart_Week.Size = new System.Drawing.Size(75, 23); + this.button_Chart_Week.TabIndex = 17; + this.button_Chart_Week.Text = "生成图表"; + this.button_Chart_Week.UseVisualStyleBackColor = true; + this.button_Chart_Week.Click += new System.EventHandler(this.button_Chart_Week_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(362, 441); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 16; + this.button1.Text = "导出报表"; + this.button1.UseVisualStyleBackColor = true; + // + // ToolStripMenuItem_load_test_data + // + this.ToolStripMenuItem_load_test_data.Name = "ToolStripMenuItem_load_test_data"; + this.ToolStripMenuItem_load_test_data.Size = new System.Drawing.Size(180, 22); + this.ToolStripMenuItem_load_test_data.Text = "载入测试数据"; + this.ToolStripMenuItem_load_test_data.Click += new System.EventHandler(this.ToolStripMenuItem_Option_LoadTestDate); + // + // 选项ToolStripMenuItem + // + this.选项ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem_load_test_data, + this.ToolStripMenuItem_PrintInternalData}); + this.选项ToolStripMenuItem.Name = "选项ToolStripMenuItem"; + this.选项ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.选项ToolStripMenuItem.Text = "选项"; + // + // 文件ToolStripMenuItem + // + this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.打开ToolStripMenuItem, + this.退出ToolStripMenuItem}); + this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; + this.文件ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.文件ToolStripMenuItem.Text = "文件"; + // + // 打开ToolStripMenuItem + // + this.打开ToolStripMenuItem.Name = "打开ToolStripMenuItem"; + this.打开ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); + this.打开ToolStripMenuItem.Text = "打开"; + this.打开ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click_File_Open); + // + // 退出ToolStripMenuItem + // + this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem"; + this.退出ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); + this.退出ToolStripMenuItem.Text = "退出"; + this.退出ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click_File_Exit); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.文件ToolStripMenuItem, + this.选项ToolStripMenuItem, + this.帮助ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(1091, 24); + this.menuStrip1.TabIndex = 15; + this.menuStrip1.Text = "menuStrip1"; + // + // 帮助ToolStripMenuItem + // + this.帮助ToolStripMenuItem.Name = "帮助ToolStripMenuItem"; + this.帮助ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.帮助ToolStripMenuItem.Text = "帮助"; + // + // Column_Count_DGV3 + // + this.Column_Count_DGV3.HeaderText = "数量"; + this.Column_Count_DGV3.Name = "Column_Count_DGV3"; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(621, 441); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 18; + this.button3.Text = "导出报表"; + this.button3.UseVisualStyleBackColor = true; + // + // Column_Mont + // + this.Column_Mont.HeaderText = "月份"; + this.Column_Mont.Name = "Column_Mont"; + // + // button_Month_Combine + // + this.button_Month_Combine.Location = new System.Drawing.Point(540, 441); + this.button_Month_Combine.Name = "button_Month_Combine"; + this.button_Month_Combine.Size = new System.Drawing.Size(75, 23); + this.button_Month_Combine.TabIndex = 13; + this.button_Month_Combine.Text = "生成年月报告"; + this.button_Month_Combine.UseVisualStyleBackColor = true; + this.button_Month_Combine.Click += new System.EventHandler(this.button_Month_Combine_Click); + // + // button_Week_Combine + // + this.button_Week_Combine.Location = new System.Drawing.Point(281, 441); + this.button_Week_Combine.Name = "button_Week_Combine"; + this.button_Week_Combine.Size = new System.Drawing.Size(75, 23); + this.button_Week_Combine.TabIndex = 12; + this.button_Week_Combine.Text = "生成年周报告"; + this.button_Week_Combine.UseVisualStyleBackColor = true; + this.button_Week_Combine.Click += new System.EventHandler(this.button_Week_Combine_Click); + // + // Column_Count_DGV2 + // + this.Column_Count_DGV2.HeaderText = "数量"; + this.Column_Count_DGV2.Name = "Column_Count_DGV2"; + // + // Column_Week + // + this.Column_Week.HeaderText = "年周"; + this.Column_Week.Name = "Column_Week"; + // + // dataGridView2 + // + this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Week, + this.Column_Count_DGV2}); + this.dataGridView2.Location = new System.Drawing.Point(281, 56); + this.dataGridView2.Name = "dataGridView2"; + this.dataGridView2.RowTemplate.Height = 23; + this.dataGridView2.Size = new System.Drawing.Size(253, 365); + this.dataGridView2.TabIndex = 11; + // + // Column_Count_DGV1 + // + this.Column_Count_DGV1.HeaderText = "数量"; + this.Column_Count_DGV1.Name = "Column_Count_DGV1"; + // + // Column_Date + // + this.Column_Date.HeaderText = "日期"; + this.Column_Date.Name = "Column_Date"; + // + // dataGridView3 + // + this.dataGridView3.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView3.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Mont, + this.Column_Count_DGV3}); + this.dataGridView3.Location = new System.Drawing.Point(540, 56); + this.dataGridView3.Name = "dataGridView3"; + this.dataGridView3.RowTemplate.Height = 23; + this.dataGridView3.Size = new System.Drawing.Size(253, 365); + this.dataGridView3.TabIndex = 14; + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Date, + this.Column_Count_DGV1}); + this.dataGridView1.Location = new System.Drawing.Point(22, 56); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 23; + this.dataGridView1.Size = new System.Drawing.Size(253, 365); + this.dataGridView1.TabIndex = 10; + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabel1, + this.toolStripDropDownButton1}); + this.statusStrip1.Location = new System.Drawing.Point(0, 522); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(1091, 22); + this.statusStrip1.TabIndex = 20; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(46, 17); + this.toolStripStatusLabel1.Text = "无数据"; + // + // toolStripDropDownButton1 + // + this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image"))); + this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 20); + this.toolStripDropDownButton1.Text = "toolStripDropDownButton1"; + // + // button_Chart_Year + // + this.button_Chart_Year.Location = new System.Drawing.Point(961, 441); + this.button_Chart_Year.Name = "button_Chart_Year"; + this.button_Chart_Year.Size = new System.Drawing.Size(75, 23); + this.button_Chart_Year.TabIndex = 24; + this.button_Chart_Year.Text = "生成图表"; + this.button_Chart_Year.UseVisualStyleBackColor = true; + this.button_Chart_Year.Click += new System.EventHandler(this.button_Chart_Year_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(880, 441); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 23; + this.button4.Text = "导出报表"; + this.button4.UseVisualStyleBackColor = true; + // + // button_Year_Combine + // + this.button_Year_Combine.Location = new System.Drawing.Point(799, 441); + this.button_Year_Combine.Name = "button_Year_Combine"; + this.button_Year_Combine.Size = new System.Drawing.Size(75, 23); + this.button_Year_Combine.TabIndex = 21; + this.button_Year_Combine.Text = "生成年度报告"; + this.button_Year_Combine.UseVisualStyleBackColor = true; + this.button_Year_Combine.Click += new System.EventHandler(this.button_Year_Combine_Click); + // + // dataGridView4 + // + this.dataGridView4.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView4.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.dataGridViewTextBoxColumn1, + this.dataGridViewTextBoxColumn2}); + this.dataGridView4.Location = new System.Drawing.Point(799, 56); + this.dataGridView4.Name = "dataGridView4"; + this.dataGridView4.RowTemplate.Height = 23; + this.dataGridView4.Size = new System.Drawing.Size(253, 365); + this.dataGridView4.TabIndex = 22; + // + // dataGridViewTextBoxColumn1 + // + this.dataGridViewTextBoxColumn1.HeaderText = "年份"; + this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1"; + // + // dataGridViewTextBoxColumn2 + // + this.dataGridViewTextBoxColumn2.HeaderText = "数量"; + this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(108, 24); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(47, 12); + this.label1.TabIndex = 25; + this.label1.Text = "日-数量"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(360, 24); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(53, 12); + this.label2.TabIndex = 26; + this.label2.Text = "按周合并"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(637, 24); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(53, 12); + this.label3.TabIndex = 27; + this.label3.Text = "按月合并"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(898, 24); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(53, 12); + this.label4.TabIndex = 28; + this.label4.Text = "按年合并"; + // + // ToolStripMenuItem_PrintInternalData + // + this.ToolStripMenuItem_PrintInternalData.Name = "ToolStripMenuItem_PrintInternalData"; + this.ToolStripMenuItem_PrintInternalData.Size = new System.Drawing.Size(180, 22); + this.ToolStripMenuItem_PrintInternalData.Text = "打印内部数据"; + this.ToolStripMenuItem_PrintInternalData.Click += new System.EventHandler(this.ToolStripMenuItem_PrintInternalData_Click); + // + // DataCombineMainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1091, 544); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button_Chart_Year); + this.Controls.Add(this.button4); + this.Controls.Add(this.button_Year_Combine); + this.Controls.Add(this.dataGridView4); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.button_Chart_Month); + this.Controls.Add(this.button_Chart_Week); + this.Controls.Add(this.button1); + this.Controls.Add(this.menuStrip1); + this.Controls.Add(this.button3); + this.Controls.Add(this.button_Month_Combine); + this.Controls.Add(this.button_Week_Combine); + this.Controls.Add(this.dataGridView2); + this.Controls.Add(this.dataGridView3); + this.Controls.Add(this.dataGridView1); + this.Name = "DataCombineMainForm"; + this.Text = "Form1"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView4)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button button_Chart_Month; + private System.Windows.Forms.Button button_Chart_Week; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_load_test_data; + private System.Windows.Forms.ToolStripMenuItem 选项ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV3; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Mont; + private System.Windows.Forms.Button button_Month_Combine; + private System.Windows.Forms.Button button_Week_Combine; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV2; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Week; + private System.Windows.Forms.DataGridView dataGridView2; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV1; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Date; + private System.Windows.Forms.DataGridView dataGridView3; + public System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.ToolStripMenuItem 打开ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 帮助ToolStripMenuItem; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1; + private System.Windows.Forms.Button button_Chart_Year; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button_Year_Combine; + private System.Windows.Forms.DataGridView dataGridView4; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn1; + private System.Windows.Forms.DataGridViewTextBoxColumn dataGridViewTextBoxColumn2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_PrintInternalData; + } +} + diff --git a/DataCombine/DataCombineMainForm.cs b/DataCombine/DataCombineMainForm.cs new file mode 100644 index 0000000000000000000000000000000000000000..a1264b73ecee0095de20c41bb852310a8478fbb1 --- /dev/null +++ b/DataCombine/DataCombineMainForm.cs @@ -0,0 +1,574 @@ +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DataCombine +{ + public enum DataCombineType + { + SameString, + DateWeek, + DateMonth, + DateYear + } + + public partial class DataCombineMainForm : Form + { + DataTable date_number_datatable; + DataTable dtWeekCombined; + DataTable dtMonthCombined; + DataTable dtYearCombined; + + public string filePath { set; get; } + FileStream stream; + public IWorkbook workbook; + public bool isCompatible; + public List activateSheetNames = new List(); + DataSet dataOfAllSheets = new DataSet(); + + public DataCombineMainForm() + { + InitializeComponent(); + } + + #region util and test + private string selectExcelFile() + { + OpenFileDialog file = new OpenFileDialog(); + file.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls"; + if (string.IsNullOrEmpty(Properties.Settings.Default.LastTimeFolder)) + { + file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + } + else + { + file.InitialDirectory = Properties.Settings.Default.LastTimeFolder; + } + + file.Multiselect = false; + + if (file.ShowDialog() == DialogResult.Cancel) + return ""; + + return file.FileName; ; + } + + public static DataTable getTestDataTable() + { + DataTable tdt = new DataTable(); + + DataColumn dateDataColumn = tdt.Columns.Add("Date"); + DataColumn countDataColumn = tdt.Columns.Add("Count"); + Random rd = new Random(); + + for (int i = 1; i <= 31; i++) + { + DataRow dr = tdt.NewRow(); + dr[0] = string.Format("2021-05-{0:D2}", i); + dr[1] = rd.Next(1000, 3000); + tdt.Rows.Add(dr); + } + + for (int i = 1; i <= 30; i++) + { + DataRow dr = tdt.NewRow(); + dr[0] = string.Format("2021/06/{0:D2}", i); + dr[1] = rd.Next(1000, 3000); + tdt.Rows.Add(dr); + } + + return tdt; + } + + public static DataTable datatableDateFormat(DataTable dt) + { + DataTable dtf = dt.Copy(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + string dateString = dt.Rows[i][0].ToString(); + Console.WriteLine(dateString); + DateTime date; + + #region Method 0 + + bool pr = DateTime.TryParse(dateString, out date); + if(pr) + { + dtf.Rows[i][0] = date; + } + else + { + MessageBox.Show("日期格式解析失败\nTODO: 需要手动修正错误\n" + dt.Rows[i][0].ToString()); + return null; + } + + #endregion + + #region Method 1 + /* + try + { + date = DateTime.Parse(dateString); + dtf.Rows[i][0] = date; + } + catch (Exception e) + { + MessageBox.Show(e.ToString() + "\nTODO: 需要手动修正错误\n" + dt.Rows[i][0].ToString()); + return null; + } + */ + #endregion + + #region Method 2 + + /*string[] formats = { "yyyy-MM-dd", "dd/MM/yyyy", "yyyy年MM月dd日", "yyyy年M月d日", "dd-MMM-yyyy" }; + //CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US"); + CultureInfo culture = CultureInfo.CreateSpecificCulture("zh_CN"); + string dateString = dt.Rows[i][0].ToString(); + Console.WriteLine(dateString); + + DateTime date; + bool r = false; + + int eceptionCount = 0; + for(int j = 0; j < formats.Length; j++ ) + { + r = DateTime.TryParseExact(dateString, formats[i], culture, DateTimeStyles.None, out date); + if(r == true) + { + dtf.Rows[i][0] = date; + break; + } else + { + eceptionCount++; + Console.WriteLine("try fail: "+ eceptionCount.ToString()); + } + } + + if (eceptionCount >= formats.Length) + { + MessageBox.Show("Find String cannot convert"); + }*/ + + #endregion + + + } + + return dtf; + } + + public static List getSelectedRowIndexs(DataGridView dgv) + { + List list = new List(); + foreach (DataGridViewRow dgvr in dgv.SelectedRows) + { + list.Add(dgvr.Index); + } + return list; + } + + private static DataTable getSelectSortTable(DataTable dti, DataGridView dgv) + { + if (dti == null || dgv == null) + { + MessageBox.Show("无数据"); + return null; + } + DataTable dto = new DataTable(); + + string c0n = dti.Columns[0].ColumnName; + dto.Columns.Add(c0n); + string c1n = dti.Columns[1].ColumnName; + dto.Columns.Add(c1n); + foreach (DataGridViewRow dgvr in dgv.SelectedRows) + { + int indexInView = dgvr.Index; + dto.ImportRow(dti.Rows[indexInView]); + } + + DataView dv = dto.DefaultView; + dv.Sort = string.Format("{0} Asc", c0n); + DataTable dts = dv.ToTable(); + + return dts; + } + + #endregion + + #region Buttons + private void button_Week_Combine_Click(object sender, EventArgs e) + { + DataTable dtf = date_number_datatable.Copy(); + + var keys = new DataColumn[1]; + dtWeekCombined = new DataTable(); + DataColumn column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.String"); + column.ColumnName = "年-周"; + dtWeekCombined.Columns.Add(column); + keys[0] = column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.Int32"); + column.ColumnName = "数量"; + dtWeekCombined.Columns.Add(column); + //keys[1] = column; + + dtWeekCombined.PrimaryKey = keys; + + for (int i = 0; i < dtf.Rows.Count; i++) + { + int value = int.Parse(dtf.Rows[i][1].ToString()); + DateTime dateOfRow = DateTime.Parse(dtf.Rows[i][0].ToString()); + + int year = dateOfRow.Year; + GregorianCalendar gc = new GregorianCalendar(); + int weekOfYear = gc.GetWeekOfYear(dateOfRow, CalendarWeekRule.FirstDay, DayOfWeek.Monday); + + string key = string.Format("{0}-{1:D2}", year, weekOfYear); + DataRow dr = dtWeekCombined.Rows.Find(key); + if (dr != null) + { + //已经有这个年-周的key了. 插入 + dr[1] = (int)dr[1] + value; + } + else + { + //新的一周, 新建一个row + DataRow newRow = dtWeekCombined.NewRow(); + newRow[0] = key; + newRow[1] = value; + dtWeekCombined.Rows.Add(newRow); + } + } + + dataGridView2.Columns.Clear(); + dataGridView2.DataSource = dtWeekCombined; + } + + private void button_Month_Combine_Click(object sender, EventArgs e) + { + DataTable dtf = date_number_datatable.Copy(); + + var keys = new DataColumn[1]; + + dtMonthCombined = new DataTable(); + DataColumn column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.String"); + column.ColumnName = "年-月"; + dtMonthCombined.Columns.Add(column); + keys[0] = column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.Int32"); + column.ColumnName = "数量"; + dtMonthCombined.Columns.Add(column); + //keys[1] = column; + + dtMonthCombined.PrimaryKey = keys; + + for (int i = 0; i < dtf.Rows.Count; i++) + { + int value = int.Parse(dtf.Rows[i][1].ToString()); + DateTime dateOfRow = DateTime.Parse(dtf.Rows[i][0].ToString()); + + int year = dateOfRow.Year; + int month = dateOfRow.Month; + //GregorianCalendar gc = new GregorianCalendar(); + //int weekOfYear = gc.GetWeekOfYear(dateOfRow, CalendarWeekRule.FirstDay, DayOfWeek.Monday); + + string key = string.Format("{0}-{1:D2}", year, month); + DataRow dr = dtMonthCombined.Rows.Find(key); + if (dr != null) + { + //已经有这个年-周的key了. 插入 + dr[1] = (int)dr[1] + value; + } + else + { + //新的一周, 新建一个row + DataRow newRow = dtMonthCombined.NewRow(); + newRow[0] = key; + newRow[1] = value; + dtMonthCombined.Rows.Add(newRow); + } + } + + dataGridView3.Columns.Clear(); + dataGridView3.DataSource = dtMonthCombined; + } + + private void button_Year_Combine_Click(object sender, EventArgs e) + { + DataTable dtf = date_number_datatable.Copy(); + + var keys = new DataColumn[1]; + dtYearCombined = new DataTable(); + DataColumn column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.String"); + column.ColumnName = "年度"; + dtYearCombined.Columns.Add(column); + keys[0] = column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.Int32"); + column.ColumnName = "数量"; + dtYearCombined.Columns.Add(column); + //keys[1] = column; + + dtYearCombined.PrimaryKey = keys; + + for (int i = 0; i < dtf.Rows.Count; i++) + { + int value = int.Parse(dtf.Rows[i][1].ToString()); + DateTime dateOfRow = DateTime.Parse(dtf.Rows[i][0].ToString()); + + int year = dateOfRow.Year; + //int month = dateOfRow.Month; + + string key = string.Format("{0}", year); + DataRow dr = dtYearCombined.Rows.Find(key); + if (dr != null) + { + //已经有这个年-周的key了. 插入 + dr[1] = (int)dr[1] + value; + } + else + { + //新的一周, 新建一个row + DataRow newRow = dtYearCombined.NewRow(); + newRow[0] = key; + newRow[1] = value; + dtYearCombined.Rows.Add(newRow); + } + } + + dataGridView4.Columns.Clear(); + dataGridView4.DataSource = dtYearCombined; + } + + private void button_Chart_Week_Click(object sender, EventArgs e) + { + Form_Chart fc = new Form_Chart(getSelectSortTable(dtWeekCombined, dataGridView2)); + fc.Show(); + } + + private void button_Chart_Month_Click(object sender, EventArgs e) + { + Form_Chart fc = new Form_Chart(getSelectSortTable(dtMonthCombined, dataGridView3)); + fc.Show(); + } + + private void button_Chart_Year_Click(object sender, EventArgs e) + { + Form_Chart fc = new Form_Chart(getSelectSortTable(dtYearCombined, dataGridView4)); + fc.Show(); + } + + #endregion + + #region menu items + + private void ToolStripMenuItem_Click_File_Open(object sender, EventArgs e) + { + #region 文件打开 + filePath = selectExcelFile(); + toolStripStatusLabel1.Text = "open file: " + filePath; + if (!File.Exists(filePath)) + { + MessageBox.Show("文件不存在,请重新选择 " + filePath); + return; + } + + string extension = Path.GetExtension(filePath); + if (!filePath.EndsWith(".xls", StringComparison.OrdinalIgnoreCase) && !filePath.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) + { + MessageBox.Show("文件扩展名错误, 请重新选择 " + extension); + return; + } + + string folder = Path.GetDirectoryName(filePath); + Properties.Settings.Default.LastTimeFolder = folder; + Properties.Settings.Default.Save(); + #endregion + + #region make workbook from file + try + { + stream = System.IO.File.OpenRead(filePath); + isCompatible = filePath.EndsWith(".xls", StringComparison.OrdinalIgnoreCase); + + if (isCompatible) + { + workbook = new HSSFWorkbook(stream); + } + else + { + workbook = new XSSFWorkbook(stream); + } + + stream.Close(); + } + catch + { + MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + finally + { + if (stream != null) + { + stream.Close(); + } + + } + + string wbVer = workbook.SpreadsheetVersion.ToString(); + string wbSheetsCount = workbook.NumberOfSheets.ToString(); + string wbInfo = string.Format("Workbook version={0} SheetCount={1}", wbVer, wbSheetsCount); + Console.WriteLine(wbInfo); + #endregion + + #region get all sheet names + activateSheetNames = ExcelHelper.GetSheetNames(workbook); + Console.WriteLine("find sheets: "); + foreach(string s in activateSheetNames) + { + Console.WriteLine(s); + } + #endregion + + #region select sheet(name) + Form_SheetSelect fss = new Form_SheetSelect(activateSheetNames); + fss.Owner = this; + + DialogResult dr = fss.ShowDialog(); + + if (dr == DialogResult.OK) + { + Console.WriteLine("sheet select ok"); + + if (activateSheetNames.Count == 0) + { + Console.WriteLine("no sheet is selected"); + return; + } + + activateSheetNames = fss.selectedSheetNames; + Console.WriteLine("selected sheets: "); + foreach (string s in activateSheetNames) + { + Console.WriteLine(s); + } + } + else + { + Console.WriteLine("sheet select cancel"); + return; + } + + #endregion + + #region Make DataTable from activate sheet names + + dataOfAllSheets = new DataSet(); + foreach (string sn in activateSheetNames) + { + ISheet sheet = workbook.GetSheet(sn); + DataTable dt = ExcelHelper.GetDataTableFromSheet(sheet, 2); + dataOfAllSheets.Tables.Add(dt); + } + Console.WriteLine("Datatable count:" + dataOfAllSheets.Tables.Count.ToString()); + #endregion + + #region load to datagridview + if (dataOfAllSheets.Tables.Count > 0) + { + date_number_datatable = dataOfAllSheets.Tables[0]; + //date_number_datatable = datatableDateFormat(dataOfAllSheets.Tables[0]); + + dataGridView1.DataSource = null; + dataGridView1.Columns.Clear(); + dataGridView1.DataSource = date_number_datatable; + + foreach (DataGridViewColumn dgvc in dataGridView1.Columns) + { + dgvc.SortMode = DataGridViewColumnSortMode.NotSortable; + } + } else + { + MessageBox.Show("没有DataTable"); + return; + } + Console.WriteLine("数据载入结束"); + #endregion + } + private void ToolStripMenuItem_Click_File_Exit(object sender, EventArgs e) + { + this.Close(); + } + private void ToolStripMenuItem_Option_LoadTestDate(object sender, EventArgs e) + { + // 拿到原始数据, 日期为字符串 + date_number_datatable = getTestDataTable(); + + foreach (DataRow dr in date_number_datatable.Rows) + { + Console.WriteLine(dr.ToString()); + } + + dataGridView1.Columns.Clear(); + dataGridView1.DataSource = date_number_datatable; + } + private void ToolStripMenuItem_PrintInternalData_Click(object sender, EventArgs e) + { + Console.WriteLine("ToolStripMenuItem_PrintInternalData_Click " + e.ToString()); + + if (date_number_datatable != null) + { + int rowCount = date_number_datatable.Rows.Count; + Console.WriteLine("内部数据共 " + rowCount.ToString() + "行"); + + if (rowCount > 0) + { + for (int rn = 0; rn < rowCount; rn++) + { + DataRow dr = date_number_datatable.Rows[rn]; + string s0 = dr[0].ToString(); + string s1 = dr[1].ToString(); + string s2 = dr[0].GetType().ToString(); + string sa = string.Format("R:<{0}> D0:<{1}> D1:<{2}> D0Type:<{3}>", rn, s0, s1, s2); + Console.WriteLine(sa); + } + } + } + else + { + Console.WriteLine("还没有载入数据"); + } + } + + #endregion + + + } +} diff --git a/DataCombine/DataCombineMainForm.resx b/DataCombine/DataCombineMainForm.resx new file mode 100644 index 0000000000000000000000000000000000000000..0d48275eb2815f930c8c228b2eb4abd12d0a1a18 --- /dev/null +++ b/DataCombine/DataCombineMainForm.resx @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + True + + + True + + + True + + + True + + + True + + + True + + + 132, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + True + + + True + + \ No newline at end of file diff --git a/DataCombine/ExampleExcelFile/example.xlsx b/DataCombine/ExampleExcelFile/example.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..556c3443f1b3f5af463bdad5eed20469d6882d20 Binary files /dev/null and b/DataCombine/ExampleExcelFile/example.xlsx differ diff --git a/DataCombine/ExcelHelper.cs b/DataCombine/ExcelHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..78f37edfbb0c3dc433042e05a8b936a9504b16fb --- /dev/null +++ b/DataCombine/ExcelHelper.cs @@ -0,0 +1,984 @@ +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Forms; +using WpfMessageBoxLibrary; + +namespace DataCombine +{ + + public static class ExcelHelper + { + #region 私有方法 + + /// + /// 获取要保存的文件名称(含完整路径) + /// + /// + //private static string GetSaveFilePath() + //{ + // SaveFileDialog saveFileDig = new SaveFileDialog(); + // saveFileDig.Filter = "Excel Office97-2003(*.xls)|.xls|Excel Office2007及以上(*.xlsx)|*.xlsx"; + // saveFileDig.FilterIndex = 0; + // saveFileDig.OverwritePrompt = true; + // saveFileDig.InitialDirectory = Common.DesktopDirectory; + // string filePath = null; + // if (saveFileDig.ShowDialog() == DialogResult.OK) + // { + // filePath = saveFileDig.FileName; + // } + + // return filePath; + //} + + /// + /// 判断是否为兼容模式 + /// + /// + /// + private static bool GetIsCompatible(string filePath) + { + return filePath.EndsWith(".xls", StringComparison.OrdinalIgnoreCase); + } + + + + /// + /// 创建工作薄 + /// + /// + /// + private static IWorkbook CreateWorkbook(bool isCompatible) + { + if (isCompatible) + { + return new HSSFWorkbook(); + } + else + { + return new XSSFWorkbook(); + } + } + + /// + /// 创建工作薄(依据文件流) + /// + /// + /// + /// + private static IWorkbook CreateWorkbook(bool isCompatible, Stream stream) + { + if (isCompatible) + { + return new HSSFWorkbook(stream); + } + else + { + return new XSSFWorkbook(stream); + } + } + + /// + /// 创建表格头单元格 + /// + /// + /// + private static ICellStyle GetCellStyle(IWorkbook workbook) + { + ICellStyle style = workbook.CreateCellStyle(); + style.FillPattern = FillPattern.SolidForeground; + style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index; + + return style; + } + + /// + /// 获取单元格类型 + /// + /// + /// + private static object GetValueType(ICell cell) + { + if (cell == null) + return null; + switch (cell.CellType) + { + case CellType.Blank: //BLANK: + return null; + case CellType.Boolean: //BOOLEAN: + return cell.BooleanCellValue; + case CellType.Numeric: //NUMERIC: + short format = cell.CellStyle.DataFormat; + if (format != 0) { + return cell.DateCellValue.ToString("yyyy-MM-dd"); + } else { + return cell.NumericCellValue; + } + case CellType.String: //STRING: + return cell.StringCellValue; + case CellType.Error: //ERROR: + return cell.ErrorCellValue; + case CellType.Formula: //FORMULA: + default: + return "=" + cell.CellFormula; + } + } + + /// + /// 从工作表中生成DataTable + /// + /// + /// + /// + public static DataTable GetDataTableFromSheet(ISheet sheet, int headerRowIndex) + { + sheet = FillSheetMergedCells(sheet, headerRowIndex); + + DataTable table = new DataTable(sheet.SheetName); + + headerRowIndex = 0; + + IRow headerRow = sheet.GetRow(headerRowIndex); + + if(headerRow == null) + { + return table; + } + + /*try + {*/ + int cellCount = headerRow.LastCellNum; + + #region Header Row + for (int i = headerRow.FirstCellNum; i < cellCount; i++) + { + //调用GetCellValue()函数 + ICell cells = headerRow.GetCell(i); //一个单元格 + string GCV = GetCellValue(cells); + + if (GCV == null || GCV.Trim() == "") + { + GCV = "Empty Cell"; + } + + DataColumn column = new DataColumn(GCV.Trim()); + try + { + table.Columns.Add(column); + } + catch + { + Console.WriteLine(string.Format("find duplicate column at s={0} c={1}", sheet.SheetName, i)); + column.ColumnName += " c" + i.ToString(); + table.Columns.Add(column); + } + } + #endregion + + #region Other Row + for (int i = (headerRowIndex + 1); i <= sheet.LastRowNum; i++) + { + #region 行有效判断 + IRow row = sheet.GetRow(i); + if(row == null) + { + System.Windows.MessageBox.Show("发现空行 行号: " + i.ToString()); + continue; + } + + ICell cell = row.GetCell(0); //一个单元格 + if (cell == null) + { + System.Windows.MessageBox.Show("发现非空行, 单行首为空单元格 行号: " + i.ToString()); + continue; + } + + string GC = GetCellValue(cell); + if (string.IsNullOrEmpty(GC)) + { + System.Windows.MessageBox.Show("发现非空行, 行首单元格仅有格式无内容 行号: " + i.ToString()); + continue; + } + #endregion + + DataRow dataRow = table.NewRow(); + + for (int j = row.FirstCellNum; j < cellCount; j++) + { + cell = row.GetCell(j); + #region method 1 + /* + if (cell != null) + { + if (cell.CellType == CellType.Formula) + { + try + { + dataRow[j] = cell.NumericCellValue; + } + catch + { + if (cell.ErrorCellValue == 7) + { + dataRow[j] = "DIV/0"; + Console.WriteLine(string.Format("find DIV/0 at s={0} r={1} c={2}", sheet.SheetName, i, j)); + } + else + { + dataRow[j] = "Error"; + } + + } + } + else if (cell.CellType == CellType.Error) + { + dataRow[j] = @"CELL_ERROR"; + Console.WriteLine(string.Format("find CELL_ERROR at s={0} r={1} c={2}", sheet.SheetName, i, j)); + } + else + { + dataRow[j] = cell.ToString(); + } + } + */ + #endregion + + #region method 2 + var x = GetValueType(cell); + + dataRow[j] = x; + #endregion + } + + table.Rows.Add(dataRow); + + } + + #endregion + /*} + catch (Exception ex) + { + Console.WriteLine("文件内容格式不对!\n\n存在空内容或者列名相同\n\n请重新选择 {0}", ex.StackTrace); + }*/ + return table; + } + + private static int GetSheetRowCount(ISheet sheet) + { + int maxCellCount = 0; + IRow row; + for (int r = 0; r < sheet.LastRowNum; r++) + { + row = sheet.GetRow(r); + if (row != null && row.LastCellNum > maxCellCount) + { + maxCellCount = row.LastCellNum; + } + } + + return maxCellCount; + } + + private static ISheet FillSheetMergedCells(ISheet sheet, int headerMergeRange) + { + Console.WriteLine("=====================sheet: " + sheet.SheetName.ToString()); + int maxCellCount = GetSheetRowCount(sheet); + + MessageBoxResult sheetIgnoreEmptyRowResult = MessageBoxResult.None; + + // method 2 + List mgs = sheet.MergedRegions; + foreach(NPOI.SS.Util.CellRangeAddress cra in mgs) + { + //Console.WriteLine("get a merge region:" + cra.NumberOfCells.ToString()); + //Console.WriteLine("merge region value: " + cra.FormatAsString()); + + for (int c = cra.FirstColumn; c <= cra.LastColumn; c++) + { + for (int r = cra.FirstRow; r <= cra.LastRow; r++) + { + ICell cell = sheet.GetRow(r).GetCell(c); + if(cell != null) + { + cell.SetCellValue(sheet.GetRow(cra.FirstRow).GetCell(cra.FirstColumn).ToString()); + } + + } + } + } + + int emptyCellCount = 0; + + for (int r = 0; r < sheet.LastRowNum; r++) + { + IRow row = sheet.GetRow(r); + + if (row == null) + { + row = sheet.CreateRow(r); + } + + if (row != null) + { + for (int c = 0; c < maxCellCount; c++) + { + ICell cell = row.GetCell(c); + if (cell == null) + { + + cell = row.CreateCell(c); + } + + if (cell != null) + { + if (string.IsNullOrEmpty(cell.ToString())) + { + if (c == 0 && sheetIgnoreEmptyRowResult == MessageBoxResult.None) + { + emptyCellCount++; + if (emptyCellCount >= 5) + { + if(Properties.Settings.Default.ignoreEmptyRow == true) + { + return sheet; + } + else + { + var msgProperties = new WpfMessageBoxProperties() + { + Button = MessageBoxButton.OKCancel, + ButtonOkText = "是(忽略)", + CheckBoxText = "后面都按此处理", + Image = MessageBoxImage.Exclamation, + Header = "表格格式不规范", + IsCheckBoxChecked = Properties.Settings.Default.ignoreEmptyRow, + IsCheckBoxVisible = true, + IsTextBoxVisible = false, + Text = "发现这个表格连续5个行首为空, 是否忽略余下部分", + Title = "表格格式不规范", + }; + sheetIgnoreEmptyRowResult = WpfMessageBox.Show(ref msgProperties); + //Console.WriteLine(result.ToString()); + bool checkBoxChecked = msgProperties.IsCheckBoxChecked; + //Console.WriteLine(checkBoxChecked.ToString()); + Properties.Settings.Default.ignoreEmptyRow = checkBoxChecked; + Properties.Settings.Default.Save(); + + if (sheetIgnoreEmptyRowResult == MessageBoxResult.OK) + { + return sheet; + } + } + } + } + + cell.SetCellValue(string.Format("EC r{0} c{1}", r, c)); + } + } + } + } + + } + return sheet; + } + + #endregion + + #region 公共导出方法 + + /// + /// 由DataSet导出Excel + /// + /// 要导出数据的DataTable + /// Excel工作表 + public static string ExportToExcel(DataSet sourceDs, string filePath) + { + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + + for (int i = 0; i < sourceDs.Tables.Count; i++) + { + DataTable table = sourceDs.Tables[i]; + string sheetName = "result" + i.ToString(); + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + // handling header. + foreach (DataColumn column in table.Columns) + { + ICell cell = headerRow.CreateCell(column.Ordinal); + cell.SetCellValue(column.ColumnName); + cell.CellStyle = cellStyle; + } + + // handling value. + int rowIndex = 1; + + foreach (DataRow row in table.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + + foreach (DataColumn column in table.Columns) + { + dataRow.CreateCell(column.Ordinal).SetCellValue((row[column] ?? "").ToString()); + } + + rowIndex++; + } + } + + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + workbook = null; + + return filePath; + + } + + + /// + /// 由DataTable导出Excel + /// + /// 要导出数据的DataTable + /// Excel工作表 + public static string ExportToExcel(DataTable sourceTable, string sheetName, string filePath) + { + if (sourceTable.Rows.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + // handling header. + foreach (DataColumn column in sourceTable.Columns) + { + ICell headerCell = headerRow.CreateCell(column.Ordinal); + headerCell.SetCellValue(column.ColumnName); + headerCell.CellStyle = cellStyle; + } + + // handling value. + int rowIndex = 1; + + foreach (DataRow row in sourceTable.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + + foreach (DataColumn column in sourceTable.Columns) + { + dataRow.CreateCell(column.Ordinal).SetCellValue((row[column] ?? "").ToString()); + } + + rowIndex++; + } + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + /// + /// 由List导出Excel + /// + /// 类型 + /// 在导出的List + /// sheet名称 + /// + public static string ExportToExcel(List data, IList> headerNameList, string sheetName, string filePath) where T : class + { + if (data.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + + for (int i = 0; i < headerNameList.Count; i++) + { + ICell cell = headerRow.CreateCell(i); + cell.SetCellValue(headerNameList[i].Value); + cell.CellStyle = cellStyle; + } + + Type t = typeof(T); + int rowIndex = 1; + foreach (T item in data) + { + IRow dataRow = sheet.CreateRow(rowIndex); + for (int n = 0; n < headerNameList.Count; n++) + { + object pValue = t.GetProperty(headerNameList[n].Key).GetValue(item, null); + dataRow.CreateCell(n).SetCellValue((pValue ?? "").ToString()); + } + rowIndex++; + } + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + /// + /// 由DataGridView导出 + /// + /// + /// + /// + /// + public static string ExportToExcel(DataGridView grid, string sheetName, string filePath) + { + if (grid.Rows.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + ISheet sheet = workbook.CreateSheet(sheetName); + + IRow headerRow = sheet.CreateRow(0); + + for (int i = 0; i < grid.Columns.Count; i++) + { + ICell cell = headerRow.CreateCell(i); + cell.SetCellValue(grid.Columns[i].Name); + cell.CellStyle = cellStyle; + } + + int rowIndex = 1; + foreach (DataGridViewRow row in grid.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + for (int n = 0; n < grid.Columns.Count; n++) + { + dataRow.CreateCell(n).SetCellValue((row.Cells[n].Value ?? "").ToString()); + } + rowIndex++; + } + + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + #endregion + + #region 公共服务方法 + + public static List GetSheetNames(string filePath) + { + List sheetNames = new List(); + + bool isCompatible; + IWorkbook wb; + FileStream stream = null; + + try + { + + stream = System.IO.File.OpenRead(filePath); + isCompatible = GetIsCompatible(filePath); + wb = CreateWorkbook(isCompatible, stream); + + for (int i = 0; i < wb.NumberOfSheets; i++) + { + string sn = wb.GetSheetName(i); + sheetNames.Add(sn); + } + + stream.Close(); + } + catch + { + System.Windows.Forms.MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + finally + { + if (stream != null) + { + stream.Close(); + } + + } + + + return sheetNames; + } + + public static List GetSheetNames(IWorkbook wb) + { + List sheetNames = new List(); + + for (int i = 0; i < wb.NumberOfSheets; i++) + { + sheetNames.Add(wb.GetSheetAt(i).SheetName); + } + + return sheetNames; + } + + + #endregion + + #region 公共导入方法 + + /// + /// 由Excel导入DataTable + /// + /// Excel文件流 + /// Excel工作表名称 + /// Excel表头行索引 + /// 是否为兼容模式 + /// DataTable + public static DataTable ImportFromExcel(Stream excelFileStream, string sheetName, int headerRowIndex, bool isCompatible) + { + IWorkbook workbook = CreateWorkbook(isCompatible, excelFileStream); + ISheet sheet = null; + int sheetIndex = -1; + if (int.TryParse(sheetName, out sheetIndex)) + { + sheet = workbook.GetSheetAt(sheetIndex); + } + else + { + sheet = workbook.GetSheet(sheetName); + } + + DataTable table = GetDataTableFromSheet(sheet, headerRowIndex); + + excelFileStream.Close(); + workbook = null; + sheet = null; + return table; + } + + /// + /// 由Excel导入DataTable + /// + /// Excel文件路径,为物理路径。 + /// Excel工作表名称 + /// Excel表头行索引 + /// DataTable + public static DataTable ImportFromExcel(string excelFilePath, string sheetName, int headerRowIndex) + { + FileStream stream = null; + try + { + stream = System.IO.File.OpenRead(excelFilePath); + bool isCompatible = GetIsCompatible(excelFilePath); + return ImportFromExcel(stream, sheetName, headerRowIndex, isCompatible); + + } + catch + { + System.Windows.Forms.MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + DataTable DT = new DataTable(); + return DT; + + } + finally + { + if(stream != null) + { + stream.Close(); + } + + } + + } + + /// + /// 由Excel导入DataSet,如果有多个工作表,则导入多个DataTable + /// + /// Excel文件流 + /// Excel表头行索引 + /// 是否为兼容模式 + /// DataSet + public static DataSet ImportFromExcel(Stream excelFileStream, int headerRowIndex, bool isCompatible) + { + DataSet ds = new DataSet(); + IWorkbook workbook = CreateWorkbook(isCompatible, excelFileStream); + for (int i = 0; i < workbook.NumberOfSheets; i++) + { + ISheet sheet = workbook.GetSheetAt(i); + DataTable table = GetDataTableFromSheet(sheet, headerRowIndex); + ds.Tables.Add(table); + } + + excelFileStream.Close(); + workbook = null; + + return ds; + } + + /// + /// 由Excel导入DataSet,如果有多个工作表,则导入多个DataTable + /// + /// Excel文件路径,为物理路径。 + /// Excel表头行索引 + /// DataSet + public static DataSet ImportFromExcel(string excelFilePath, int headerRowIndex) + { + FileStream stream = null; + try + { + stream = System.IO.File.OpenRead(excelFilePath); + + bool isCompatible = GetIsCompatible(excelFilePath); + return ImportFromExcel(stream, headerRowIndex, isCompatible); + } + catch + { + System.Windows.MessageBox.Show("请关闭文件,再导入!", "提示", (MessageBoxButton)MessageBoxButtons.OK, (MessageBoxImage)MessageBoxIcon.Warning); + DataSet ds = new DataSet(); + return ds; + } + finally + { + if(stream != null) + { + stream.Close(); + } + } + } + + #endregion + + #region 公共转换方法 + + /// + /// 将Excel的列索引转换为列名,列索引从0开始,列名从A开始。如第0列为A,第1列为B... + /// + /// 列索引 + /// 列名,如第0列为A,第1列为B... + public static string ConvertColumnIndexToColumnName(int index) + { + index = index + 1; + int system = 26; + char[] digArray = new char[100]; + int i = 0; + while (index > 0) + { + int mod = index % system; + if (mod == 0) mod = system; + digArray[i++] = (char)(mod - 1 + 'A'); + index = (index - 1) / 26; + } + StringBuilder sb = new StringBuilder(i); + for (int j = i - 1; j >= 0; j--) + { + sb.Append(digArray[j]); + } + return sb.ToString(); + } + + + /// + /// 转化日期 + /// + /// 日期 + /// + public static DateTime ConvertDate(object date) + { + string dtStr = (date ?? "").ToString(); + + DateTime dt = new DateTime(); + + if (DateTime.TryParse(dtStr, out dt)) + { + return dt; + } + + try + { + string spStr = ""; + if (dtStr.Contains("-")) + { + spStr = "-"; + } + else if (dtStr.Contains("/")) + { + spStr = "/"; + } + string[] time = dtStr.Split(spStr.ToCharArray()); + int year = Convert.ToInt32(time[2]); + int month = Convert.ToInt32(time[0]); + int day = Convert.ToInt32(time[1]); + string years = Convert.ToString(year); + string months = Convert.ToString(month); + string days = Convert.ToString(day); + if (months.Length == 4) + { + dt = Convert.ToDateTime(date); + } + else + { + string rq = ""; + if (years.Length == 1) + { + years = "0" + years; + } + if (months.Length == 1) + { + months = "0" + months; + } + if (days.Length == 1) + { + days = "0" + days; + } + rq = "20" + years + "-" + months + "-" + days; + dt = Convert.ToDateTime(rq); + } + } + catch + { + throw new Exception("日期格式不正确,转换日期失败!"); + } + return dt; + } + + /// + /// 转化数字 + /// + /// 数字字符串 + /// + public static decimal ConvertDecimal(object d) + { + string dStr = (d ?? "").ToString(); + decimal result = 0; + if (decimal.TryParse(dStr, out result)) + { + return result; + } + else + { + throw new Exception("数字格式不正确,转换数字失败!"); + } + + } + + #endregion + + #region 数值转换string + private static string GetCellValue(ICell cell) + { + /* + * if (cell == null) + return string.Empty; + switch (cell.CellType) + { + case CellType.Blank: //空数据类型 这里类型注意一下,不同版本NPOI大小写可能不一样,有的版本是Blank(首字母大写) + return string.Empty; + case CellType.Boolean: //bool类型 + return cell.BooleanCellValue.ToString(); + case CellType.Error: + return cell.ErrorCellValue.ToString(); + case CellType.Numeric: //数字类型 + if (HSSFDateUtil.IsCellDateFormatted(cell))//日期类型 + { + return cell.DateCellValue.ToString(); + } + else //其它数字 + { + return cell.NumericCellValue.ToString(); + } + case CellType.Unknown: //无法识别类型 + default: //默认类型 + return cell.ToString();// + case CellType.String: //string 类型 + return cell.StringCellValue; + case CellType.Formula: //带公式类型 + try + { + HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook); + e.EvaluateInCell(cell); + return cell.ToString(); + } + catch + { + return cell.NumericCellValue.ToString(); + } + }*/ + //Console.WriteLine(cell.Sheet.SheetName + " row=" + cell.Row.ToString() + " col=" + cell.ColumnIndex.ToString()); + + + + + if (cell == null) + { + //Console.WriteLine("Empty Cell"); + return "Empty Cell"; + } + else + { + if (cell.IsMergedCell) + { + //Console.WriteLine("we find a merged cell"); + } + + //Console.WriteLine(cell.ToString()); + return cell.ToString(); + } + } + #endregion + } +} diff --git a/DataCombine/Form_Chart.Designer.cs b/DataCombine/Form_Chart.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..9ed01e2cad1df2d89bb2b7847a1999f23cefebed --- /dev/null +++ b/DataCombine/Form_Chart.Designer.cs @@ -0,0 +1,205 @@ +namespace DataCombine +{ + partial class Form_Chart + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); + System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); + System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form_Chart)); + this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.button_save_chart = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBox_chart_selections = new System.Windows.Forms.ComboBox(); + this.contextMenuStrip_save_chart = new System.Windows.Forms.ContextMenuStrip(this.components); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton(); + this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripDropDownButton2 = new System.Windows.Forms.ToolStripDropDownButton(); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // chart1 + // + this.chart1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + chartArea1.Name = "ChartArea1"; + this.chart1.ChartAreas.Add(chartArea1); + legend1.Name = "Legend1"; + this.chart1.Legends.Add(legend1); + this.chart1.Location = new System.Drawing.Point(12, 12); + this.chart1.Name = "chart1"; + series1.ChartArea = "ChartArea1"; + series1.Legend = "Legend1"; + series1.Name = "Series1"; + this.chart1.Series.Add(series1); + this.chart1.Size = new System.Drawing.Size(577, 406); + this.chart1.TabIndex = 0; + this.chart1.Text = "chart1"; + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.button_save_chart); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Controls.Add(this.comboBox_chart_selections); + this.groupBox1.Location = new System.Drawing.Point(595, 13); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(193, 425); + this.groupBox1.TabIndex = 1; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "groupBox1"; + // + // button_save_chart + // + this.button_save_chart.Location = new System.Drawing.Point(66, 382); + this.button_save_chart.Name = "button_save_chart"; + this.button_save_chart.Size = new System.Drawing.Size(75, 23); + this.button_save_chart.TabIndex = 5; + this.button_save_chart.Text = "保存为图片"; + this.button_save_chart.UseVisualStyleBackColor = true; + this.button_save_chart.Click += new System.EventHandler(this.button_save_chart_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(79, 284); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 4; + this.label1.Text = "label1"; + // + // comboBox_chart_selections + // + this.comboBox_chart_selections.FormattingEnabled = true; + this.comboBox_chart_selections.Items.AddRange(new object[] { + "柱状图", + "折线图", + "饼状图", + "雷达图", + "曲线图", + "柱状图(横)", + "甜甜圈"}); + this.comboBox_chart_selections.Location = new System.Drawing.Point(36, 20); + this.comboBox_chart_selections.Name = "comboBox_chart_selections"; + this.comboBox_chart_selections.Size = new System.Drawing.Size(121, 20); + this.comboBox_chart_selections.TabIndex = 3; + this.comboBox_chart_selections.Text = "柱状图"; + this.comboBox_chart_selections.SelectedIndexChanged += new System.EventHandler(this.comboBox_chart_selections_SelectedIndexChanged); + // + // contextMenuStrip_save_chart + // + this.contextMenuStrip_save_chart.Name = "contextMenuStrip_save_chart"; + this.contextMenuStrip_save_chart.Size = new System.Drawing.Size(61, 4); + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabel1, + this.toolStripDropDownButton1, + this.toolStripStatusLabel2, + this.toolStripDropDownButton2}); + this.statusStrip1.Location = new System.Drawing.Point(0, 428); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(800, 22); + this.statusStrip1.TabIndex = 2; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(118, 17); + this.toolStripStatusLabel1.Text = "toolStripStatusLabel1"; + // + // toolStripDropDownButton1 + // + this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image"))); + this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 20); + this.toolStripDropDownButton1.Text = "toolStripDropDownButton1"; + // + // toolStripStatusLabel2 + // + this.toolStripStatusLabel2.Name = "toolStripStatusLabel2"; + this.toolStripStatusLabel2.Size = new System.Drawing.Size(118, 17); + this.toolStripStatusLabel2.Text = "toolStripStatusLabel2"; + // + // toolStripDropDownButton2 + // + this.toolStripDropDownButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripDropDownButton2.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton2.Image"))); + this.toolStripDropDownButton2.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripDropDownButton2.Name = "toolStripDropDownButton2"; + this.toolStripDropDownButton2.Size = new System.Drawing.Size(29, 20); + this.toolStripDropDownButton2.Text = "toolStripDropDownButton2"; + // + // Form_Chart + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.chart1); + this.Name = "Form_Chart"; + this.Text = "Form_Chart"; + this.Load += new System.EventHandler(this.Form_Chart_Load); + ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataVisualization.Charting.Chart chart1; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.ComboBox comboBox_chart_selections; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button_save_chart; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip_save_chart; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2; + private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton2; + } +} \ No newline at end of file diff --git a/DataCombine/Form_Chart.cs b/DataCombine/Form_Chart.cs new file mode 100644 index 0000000000000000000000000000000000000000..aa38ba16b1a851a4c8f6b90fd7ce39abcd7dc03a --- /dev/null +++ b/DataCombine/Form_Chart.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; +using System.Windows.Forms.DataVisualization.Charting; + +namespace DataCombine +{ + public partial class Form_Chart : Form + { + DataTable chartDataSource; + public Form_Chart() + { + InitializeComponent(); + } + + public Form_Chart(DataTable dt) + { + chartDataSource = dt; + InitializeComponent(); + } + + private void Form_Chart_Load(object sender, EventArgs e) + { + #region 显示chart + DataTable dt = chartDataSource; + + if(dt == null) + { + MessageBox.Show("未加载数据,无法生成图表"); + return; + } + + if (dt.Columns.Count <= 1) + { + MessageBox.Show("源数据只有小于等于1列,无法生成图表"); + return; + } + + int sc = chart1.Series.Count; + + chart1.Series[0].Name = dt.Columns[0].ColumnName; + + + for (int i = sc; i < dt.Columns.Count; i++) + { + Console.WriteLine(dt.Columns[i].ColumnName); + chart1.Series.Add(dt.Columns[i].ColumnName); + } + + chart1.DataSource = dt; + + chart1.Series[0].XValueMember = dt.Columns[0].ColumnName; + + for(int i = 1; i < dt.Columns.Count; i++) + { + Console.WriteLine(dt.Columns[i].ColumnName); + chart1.Series[i-1].YValueMembers = dt.Columns[i].ColumnName; + } + + chart1.DataBind(); + #endregion + + #region combobox data load + //SeriesChartType + comboBox_chart_selections.DataSource = System.Enum.GetNames(typeof(SeriesChartType)); + comboBox_chart_selections.SelectedIndex = 11; + #endregion + + + } + + private DataTable CreateDataTable() + { + DataTable dt = new DataTable(); + dt.Columns.Add("Date"); + dt.Columns.Add("Volume1"); + dt.Columns.Add("Volume2"); + dt.Columns.Add("Volume3"); + + DataRow dr; + + dr = dt.NewRow(); + dr["Date"] = "Jan"; + dr["Volume1"] = 12333; + dr["Volume2"] = 4111; + dr["Volume3"] = 33; + dt.Rows.Add(dr); + + dr = dt.NewRow(); + dr["Date"] = "Feb"; + dr["Volume1"] = 7333; + dr["Volume2"] = 5111; + dr["Volume3"] = 73; + dt.Rows.Add(dr); + + dr = dt.NewRow(); + dr["Date"] = "Mar"; + dr["Volume1"] = 12333; + dr["Volume2"] = 4111; + dr["Volume3"] = 33; + dt.Rows.Add(dr); + + dr = dt.NewRow(); + dr["Date"] = "Apr"; + dr["Volume1"] = 7333; + dr["Volume2"] = 5111; + dr["Volume3"] = 73; + dt.Rows.Add(dr); + + return dt; + + } + + private void button_save_chart_Click(object sender, EventArgs e) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|SVG (*.svg)|*.svg|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif"; + sfd.FilterIndex = 2; + sfd.RestoreDirectory = true; + DialogResult r = sfd.ShowDialog(); + + if (r == DialogResult.OK) + { + ChartImageFormat format = ChartImageFormat.Bmp; + + if (sfd.FileName.EndsWith("bmp")) + { + format = ChartImageFormat.Bmp; + } + else if (sfd.FileName.EndsWith("jpg")) + { + format = ChartImageFormat.Jpeg; + } + else if (sfd.FileName.EndsWith("emf")) + { + format = ChartImageFormat.Emf; + } + else if (sfd.FileName.EndsWith("gif")) + { + format = ChartImageFormat.Gif; + } + else if (sfd.FileName.EndsWith("png")) + { + format = ChartImageFormat.Png; + } + else if (sfd.FileName.EndsWith("tif")) + { + format = ChartImageFormat.Tiff; + } + /*else if (sfd.FileName.EndsWith("svg")) + { + format = ChartImageFormat.Svg; + }*/ + + // Save image + chart1.SaveImage(sfd.FileName, format); + } + } + + private void comboBox_chart_selections_SelectedIndexChanged(object sender, EventArgs e) + { + string selectText = comboBox_chart_selections.SelectedItem.ToString(); + int selectIndex = comboBox_chart_selections.SelectedIndex; + string log = string.Format("comboBox_chart_selections_SelectedIndexChanged {0} {1}", selectText, selectIndex); + Console.WriteLine(log); + + chart1.Series[0].ChartType = (SeriesChartType)selectIndex; + chart1.Series[1].ChartType = (SeriesChartType)selectIndex; + } + } +} diff --git a/DataCombine/Form_Chart.resx b/DataCombine/Form_Chart.resx new file mode 100644 index 0000000000000000000000000000000000000000..af679f468490730981cc0af50a682739074f86a8 --- /dev/null +++ b/DataCombine/Form_Chart.resx @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 227, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + \ No newline at end of file diff --git a/DataCombine/Form_SelectYearMonth.Designer.cs b/DataCombine/Form_SelectYearMonth.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..d35a0ead4152c2de11860da368459e8d4240c90e --- /dev/null +++ b/DataCombine/Form_SelectYearMonth.Designer.cs @@ -0,0 +1,105 @@ +namespace DataCombine +{ + partial class Form_SelectYearMonth + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button_OK = new System.Windows.Forms.Button(); + this.button_Cancel = new System.Windows.Forms.Button(); + this.dateTimePicker_Year = new System.Windows.Forms.DateTimePicker(); + this.dateTimePicker_Month = new System.Windows.Forms.DateTimePicker(); + this.SuspendLayout(); + // + // button_OK + // + this.button_OK.Location = new System.Drawing.Point(149, 192); + this.button_OK.Name = "button_OK"; + this.button_OK.Size = new System.Drawing.Size(75, 23); + this.button_OK.TabIndex = 2; + this.button_OK.Text = "确定"; + this.button_OK.UseVisualStyleBackColor = true; + this.button_OK.Click += new System.EventHandler(this.button_OK_Click); + // + // button_Cancel + // + this.button_Cancel.Location = new System.Drawing.Point(308, 192); + this.button_Cancel.Name = "button_Cancel"; + this.button_Cancel.Size = new System.Drawing.Size(75, 23); + this.button_Cancel.TabIndex = 3; + this.button_Cancel.Text = "取消"; + this.button_Cancel.UseVisualStyleBackColor = true; + this.button_Cancel.Click += new System.EventHandler(this.button_Cancel_Click); + // + // dateTimePicker_Year + // + this.dateTimePicker_Year.CustomFormat = "yyyy"; + this.dateTimePicker_Year.Font = new System.Drawing.Font("Microsoft YaHei", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.dateTimePicker_Year.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker_Year.Location = new System.Drawing.Point(105, 68); + this.dateTimePicker_Year.Name = "dateTimePicker_Year"; + this.dateTimePicker_Year.ShowUpDown = true; + this.dateTimePicker_Year.Size = new System.Drawing.Size(119, 43); + this.dateTimePicker_Year.TabIndex = 4; + this.dateTimePicker_Year.ValueChanged += new System.EventHandler(this.dateTimePicker_Year_ValueChanged); + // + // dateTimePicker_Month + // + this.dateTimePicker_Month.CustomFormat = "MM"; + this.dateTimePicker_Month.Font = new System.Drawing.Font("Microsoft YaHei", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.dateTimePicker_Month.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker_Month.Location = new System.Drawing.Point(293, 68); + this.dateTimePicker_Month.Name = "dateTimePicker_Month"; + this.dateTimePicker_Month.RightToLeftLayout = true; + this.dateTimePicker_Month.ShowUpDown = true; + this.dateTimePicker_Month.Size = new System.Drawing.Size(124, 43); + this.dateTimePicker_Month.TabIndex = 5; + this.dateTimePicker_Month.ValueChanged += new System.EventHandler(this.dateTimePicker_Month_ValueChanged); + // + // Form_SelectYearMonth + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(524, 264); + this.Controls.Add(this.dateTimePicker_Month); + this.Controls.Add(this.dateTimePicker_Year); + this.Controls.Add(this.button_Cancel); + this.Controls.Add(this.button_OK); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "Form_SelectYearMonth"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Text = "Form_SelectYearMonth"; + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button button_OK; + private System.Windows.Forms.Button button_Cancel; + private System.Windows.Forms.DateTimePicker dateTimePicker_Year; + private System.Windows.Forms.DateTimePicker dateTimePicker_Month; + } +} \ No newline at end of file diff --git a/DataCombine/Form_SelectYearMonth.cs b/DataCombine/Form_SelectYearMonth.cs new file mode 100644 index 0000000000000000000000000000000000000000..254598c309fe1f058bdb3cc38d30b430904718da --- /dev/null +++ b/DataCombine/Form_SelectYearMonth.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DataCombine +{ + public partial class Form_SelectYearMonth : Form + { + public DateTime dateTime { get; set; } + + public Form_SelectYearMonth() + { + InitializeComponent(); + } + + public Form_SelectYearMonth(DateTime dt) + { + dateTime = dt; + InitializeComponent(); + + dateTimePicker_Year.Value = dt; + dateTimePicker_Month.Value = dt; + Console.WriteLine(dt); + } + + private void button_OK_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void button_Cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void dateTimePicker_Year_ValueChanged(object sender, EventArgs e) + { + int yyyy = dateTimePicker_Year.Value.Year; + int MM = dateTimePicker_Month.Value.Month; + dateTime = new DateTime(yyyy, MM, 1); + } + + private void dateTimePicker_Month_ValueChanged(object sender, EventArgs e) + { + int yyyy = dateTimePicker_Year.Value.Year; + int MM = dateTimePicker_Month.Value.Month; + dateTime = new DateTime(yyyy, MM, 1); + } + } +} diff --git a/DataCombine/Form_SelectYearMonth.resx b/DataCombine/Form_SelectYearMonth.resx new file mode 100644 index 0000000000000000000000000000000000000000..1af7de150c99c12dd67a509fe57c10d63e4eeb04 --- /dev/null +++ b/DataCombine/Form_SelectYearMonth.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataCombine/Form_SheetSelect.Designer.cs b/DataCombine/Form_SheetSelect.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..409c2669797c9b14ad3e9e0e2d23469e18dad479 --- /dev/null +++ b/DataCombine/Form_SheetSelect.Designer.cs @@ -0,0 +1,144 @@ +namespace DataCombine +{ + partial class Form_SheetSelect + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.SheetName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.YearMonth = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Process = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.button_end_ok = new System.Windows.Forms.Button(); + this.button_end_cancel = new System.Windows.Forms.Button(); + this.button_select_all = new System.Windows.Forms.Button(); + this.button_disselect_all = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.SheetName, + this.YearMonth, + this.Process}); + this.dataGridView1.Location = new System.Drawing.Point(12, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 23; + this.dataGridView1.Size = new System.Drawing.Size(540, 426); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick); + this.dataGridView1.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseDoubleClick); + // + // SheetName + // + this.SheetName.HeaderText = "SheetName"; + this.SheetName.Name = "SheetName"; + // + // YearMonth + // + this.YearMonth.HeaderText = "YearMonth"; + this.YearMonth.Name = "YearMonth"; + // + // Process + // + this.Process.HeaderText = "Process"; + this.Process.Name = "Process"; + this.Process.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.Process.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + // + // button_end_ok + // + this.button_end_ok.Location = new System.Drawing.Point(619, 322); + this.button_end_ok.Name = "button_end_ok"; + this.button_end_ok.Size = new System.Drawing.Size(119, 33); + this.button_end_ok.TabIndex = 1; + this.button_end_ok.Text = "确定"; + this.button_end_ok.UseVisualStyleBackColor = true; + this.button_end_ok.Click += new System.EventHandler(this.button_end_ok_Click); + // + // button_end_cancel + // + this.button_end_cancel.Location = new System.Drawing.Point(619, 380); + this.button_end_cancel.Name = "button_end_cancel"; + this.button_end_cancel.Size = new System.Drawing.Size(119, 33); + this.button_end_cancel.TabIndex = 2; + this.button_end_cancel.Text = "取消"; + this.button_end_cancel.UseVisualStyleBackColor = true; + this.button_end_cancel.Click += new System.EventHandler(this.button_end_cancel_Click); + // + // button_select_all + // + this.button_select_all.Location = new System.Drawing.Point(585, 12); + this.button_select_all.Name = "button_select_all"; + this.button_select_all.Size = new System.Drawing.Size(75, 23); + this.button_select_all.TabIndex = 7; + this.button_select_all.Text = "全选"; + this.button_select_all.UseVisualStyleBackColor = true; + this.button_select_all.Click += new System.EventHandler(this.button_select_all_Click); + // + // button_disselect_all + // + this.button_disselect_all.Location = new System.Drawing.Point(678, 12); + this.button_disselect_all.Name = "button_disselect_all"; + this.button_disselect_all.Size = new System.Drawing.Size(75, 23); + this.button_disselect_all.TabIndex = 8; + this.button_disselect_all.Text = "全不选"; + this.button_disselect_all.UseVisualStyleBackColor = true; + this.button_disselect_all.Click += new System.EventHandler(this.button_disselect_all_Click); + // + // Form_SheetSelect + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button_disselect_all); + this.Controls.Add(this.button_select_all); + this.Controls.Add(this.button_end_cancel); + this.Controls.Add(this.button_end_ok); + this.Controls.Add(this.dataGridView1); + this.Name = "Form_SheetSelect"; + this.Text = "Form_SheetSelect"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form_SheetSelect_FormClosing); + this.Load += new System.EventHandler(this.Form_SheetSelect_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn SheetName; + private System.Windows.Forms.DataGridViewTextBoxColumn YearMonth; + private System.Windows.Forms.DataGridViewCheckBoxColumn Process; + private System.Windows.Forms.Button button_end_ok; + private System.Windows.Forms.Button button_end_cancel; + private System.Windows.Forms.Button button_select_all; + private System.Windows.Forms.Button button_disselect_all; + } +} \ No newline at end of file diff --git a/DataCombine/Form_SheetSelect.cs b/DataCombine/Form_SheetSelect.cs new file mode 100644 index 0000000000000000000000000000000000000000..31e68c9114ba6db0054f22435a4bf2a20ef91bd6 --- /dev/null +++ b/DataCombine/Form_SheetSelect.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows.Forms; + +namespace DataCombine +{ + public partial class Form_SheetSelect : Form + { + DataCombineMainForm mainForm; + + public List originSheetNames { get; set; } + public List selectedSheetNames { get; set; } + + public List selectedSheetYearMonth { get; set; } + + public Form_SheetSelect() + { + InitializeComponent(); + + } + + public Form_SheetSelect(List sheetNames) + { + originSheetNames = sheetNames; + InitializeComponent(); + } + + private void button_end_ok_Click(object sender, EventArgs e) + { + // 检查年月列, 如果选中的有重复, 不退出 + Console.WriteLine("button_end_ok_Click"); + selectedSheetNames = new List(); + + foreach (DataGridViewRow dgvr in dataGridView1.Rows) + { + if (dgvr.Cells[2] is DataGridViewCheckBoxCell) + { + if ((bool)((DataGridViewCheckBoxCell)dgvr.Cells[2]).FormattedValue == true) + { + Console.WriteLine(dgvr.Cells[0].Value.ToString()); + selectedSheetNames.Add(dgvr.Cells[0].Value.ToString()); + } + } + } + + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void button_end_cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void Form_SheetSelect_Load(object sender, EventArgs e) + { + dataGridView1.DataSource = null; //每次打开清空内容 + + mainForm = (DataCombineMainForm)this.Owner; + + if(originSheetNames.Count <= 0) + { + MessageBox.Show("文件没有任何sheet"); + return; + } + + for(int i = 0; i < originSheetNames.Count; i++) + { + string sn = originSheetNames[i]; + //Console.WriteLine(sn); + int index = this.dataGridView1.Rows.Add(); + this.dataGridView1.Rows[index].Cells[0].Value = sn; + + DateTime dt = DateTime.Today; + string yyyyMM = dt.ToString("yyyy-MM"); + this.dataGridView1.Rows[index].Cells[1].Value = yyyyMM; + this.dataGridView1.Rows[index].Cells[2].Value = false; + } + } + + private void Form_SheetSelect_FormClosing(object sender, FormClosingEventArgs e) + { + + } + + private void button_select_all_Click(object sender, EventArgs e) + { + for(int i = 0; i < dataGridView1.Rows.Count -1; i++) + { + DataGridViewRow dgvr = dataGridView1.Rows[i]; + if(dgvr != null) + { + dgvr.Cells[2].Value = true; + } + } + } + + private void button_disselect_all_Click(object sender, EventArgs e) + { + for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) + { + DataGridViewRow dgvr = dataGridView1.Rows[i]; + if (dgvr != null) + { + dgvr.Cells[2].Value = false; + } + } + } + + private void button_guess_year_month_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow dgvr in dataGridView1.Rows) + { + if(dgvr.IsNewRow) + { + continue; + } + string sheetName = dgvr.Cells[0].Value.ToString(); + // Console.WriteLine(sheetName+ " === " +Util.GuessMonth(sheetName).ToString()); + + } + } + + private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + if(e.Button == MouseButtons.Right) + { + string s = string.Format("m-r click R{0} C{1}", e.RowIndex, e.ColumnIndex); + Console.WriteLine(s); + } + } + + private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) + { + string s = string.Format("m-2c click R{0} C{1}", e.RowIndex, e.ColumnIndex); + Console.WriteLine(s); + + if(e.ColumnIndex == 1) + { + string cellContent = (string)dataGridView1[e.ColumnIndex, e.RowIndex].Value; + DateTime dt = DateTime.ParseExact(cellContent, "yyyy-MM", CultureInfo.CurrentCulture, DateTimeStyles.None); + + Form_SelectYearMonth fsym = new Form_SelectYearMonth(dt); + fsym.Owner = this; + fsym.ShowDialog(); + + dt = fsym.dateTime; + Console.WriteLine(dt); + + cellContent = dt.ToString("yyyy-MM"); + dataGridView1[e.ColumnIndex, e.RowIndex].Value = cellContent; + + dataGridView1[e.ColumnIndex, e.RowIndex].Selected = false; + dataGridView1[e.ColumnIndex, e.RowIndex].Selected = true; + //dataGridView1[e.ColumnIndex, e.RowIndex]. + dataGridView1.EndEdit(); + } + + + } + } +} diff --git a/DataCombine/Form_SheetSelect.resx b/DataCombine/Form_SheetSelect.resx new file mode 100644 index 0000000000000000000000000000000000000000..e6b7f21869919e0aca317b9c92b1890600426b7b --- /dev/null +++ b/DataCombine/Form_SheetSelect.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/DataCombine/Program.cs b/DataCombine/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..3b1b7b5f1591602cc8b46bec20c6b97f9720a1cf --- /dev/null +++ b/DataCombine/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DataCombine +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new DataCombineMainForm()); + } + } +} diff --git a/DataCombine/Properties/AssemblyInfo.cs b/DataCombine/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000000000000000000000000000000000..4accb0985f630d44ece079e447bf2f89bae90ea7 --- /dev/null +++ b/DataCombine/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("DataCombine")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DataCombine")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7f22de22-1a7d-4817-8a66-38179a5828c4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DataCombine/Properties/Resources.Designer.cs b/DataCombine/Properties/Resources.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..8804f5f4af0f32c74d8ef3e4098ddc837eeb91c3 --- /dev/null +++ b/DataCombine/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DataCombine.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DataCombine.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/DataCombine/Properties/Resources.resx b/DataCombine/Properties/Resources.resx new file mode 100644 index 0000000000000000000000000000000000000000..af7dbebbacef595e3089c01c05671016c21a8304 --- /dev/null +++ b/DataCombine/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DataCombine/Properties/Settings.Designer.cs b/DataCombine/Properties/Settings.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..7a4505c28ac46c55c990da414f89517318fc2e48 --- /dev/null +++ b/DataCombine/Properties/Settings.Designer.cs @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace DataCombine.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.6.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string LastTimeFolder { + get { + return ((string)(this["LastTimeFolder"])); + } + set { + this["LastTimeFolder"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ignoreEmptyRow { + get { + return ((bool)(this["ignoreEmptyRow"])); + } + set { + this["ignoreEmptyRow"] = value; + } + } + } +} diff --git a/DataCombine/Properties/Settings.settings b/DataCombine/Properties/Settings.settings new file mode 100644 index 0000000000000000000000000000000000000000..3ae84d1c07efba77a24445329bdf11bfc4baa572 --- /dev/null +++ b/DataCombine/Properties/Settings.settings @@ -0,0 +1,12 @@ + + + + + + + + + False + + + \ No newline at end of file diff --git a/DataCombine/packages.config b/DataCombine/packages.config new file mode 100644 index 0000000000000000000000000000000000000000..ccf43ed53c821cbce77e69ce76e2ce688946156e --- /dev/null +++ b/DataCombine/packages.config @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ExcelToChart/ExcelHelper.cs b/ExcelToChart/ExcelHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..02610c67b8b6ba96d863500ef0b9d41324dcfb24 --- /dev/null +++ b/ExcelToChart/ExcelHelper.cs @@ -0,0 +1,923 @@ +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Forms; +using WpfMessageBoxLibrary; + +namespace ExcelToChart +{ + + public static class ExcelHelper + { + #region 私有方法 + + /// + /// 获取要保存的文件名称(含完整路径) + /// + /// + //private static string GetSaveFilePath() + //{ + // SaveFileDialog saveFileDig = new SaveFileDialog(); + // saveFileDig.Filter = "Excel Office97-2003(*.xls)|.xls|Excel Office2007及以上(*.xlsx)|*.xlsx"; + // saveFileDig.FilterIndex = 0; + // saveFileDig.OverwritePrompt = true; + // saveFileDig.InitialDirectory = Common.DesktopDirectory; + // string filePath = null; + // if (saveFileDig.ShowDialog() == DialogResult.OK) + // { + // filePath = saveFileDig.FileName; + // } + + // return filePath; + //} + + /// + /// 判断是否为兼容模式 + /// + /// + /// + private static bool GetIsCompatible(string filePath) + { + return filePath.EndsWith(".xls", StringComparison.OrdinalIgnoreCase); + } + + + + /// + /// 创建工作薄 + /// + /// + /// + private static IWorkbook CreateWorkbook(bool isCompatible) + { + if (isCompatible) + { + return new HSSFWorkbook(); + } + else + { + return new XSSFWorkbook(); + } + } + + /// + /// 创建工作薄(依据文件流) + /// + /// + /// + /// + private static IWorkbook CreateWorkbook(bool isCompatible, Stream stream) + { + if (isCompatible) + { + return new HSSFWorkbook(stream); + } + else + { + return new XSSFWorkbook(stream); + } + } + + /// + /// 创建表格头单元格 + /// + /// + /// + private static ICellStyle GetCellStyle(IWorkbook workbook) + { + ICellStyle style = workbook.CreateCellStyle(); + style.FillPattern = FillPattern.SolidForeground; + style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index; + + return style; + } + + + /// + /// 从工作表中生成DataTable + /// + /// + /// + /// + public static DataTable GetDataTableFromSheet(ISheet sheet, int headerRowIndex) + { + sheet = FillSheetMergedCells(sheet, headerRowIndex); + + DataTable table = new DataTable(sheet.SheetName); + + headerRowIndex = 0; + + IRow headerRow = sheet.GetRow(headerRowIndex); + + if(headerRow == null) + { + return table; + } + + /*try + {*/ + int cellCount = headerRow.LastCellNum; + + for (int i = headerRow.FirstCellNum; i < cellCount; i++) + { + //调用GetCellValue()函数 + ICell cells = headerRow.GetCell(i); //一个单元格 + string GCV = GetCellValue(cells); + + if (GCV == null || GCV.Trim() == "") + { + GCV = "Empty Cell"; + } + DataColumn column = new DataColumn(GCV.Trim()); + try + { + table.Columns.Add(column); + } + catch + { + Console.WriteLine(string.Format("find duplicate column at s={0} c={1}", sheet.SheetName, i)); + column.ColumnName += " c" + i.ToString(); + table.Columns.Add(column); + } + } + + for (int i = (headerRowIndex + 1); i <= sheet.LastRowNum; i++) + { + IRow row = sheet.GetRow(i); + + ICell cell = row.GetCell(0); //一个单元格 + string GC = GetCellValue(cell); + + // if (row != null && !string.IsNullOrEmpty(row.Cells[0].StringCellValue)) + if (row != null && !string.IsNullOrEmpty(GC)) + { + DataRow dataRow = table.NewRow(); + + for (int j = row.FirstCellNum; j < cellCount; j++) + { + if (row.GetCell(j) != null) + { + cell = row.GetCell(j); + //Console.WriteLine("r="+i.ToString()+"c="+j.ToString()+" "+dataRow[j]); + if (cell.CellType == CellType.Formula) + { + try + { + dataRow[j] = cell.NumericCellValue; + } + catch + { + if (cell.ErrorCellValue == 7) + { + dataRow[j] = "DIV/0"; + Console.WriteLine(string.Format("find DIV/0 at s={0} r={1} c={2}", sheet.SheetName, i, j)); + } + else + { + dataRow[j] = "Error"; + } + + } + } + else if (cell.CellType == CellType.Error) + { + dataRow[j] = @"CELL_ERROR"; + Console.WriteLine(string.Format("find CELL_ERROR at s={0} r={1} c={2}", sheet.SheetName, i, j)); + } + else + { + dataRow[j] = cell.ToString(); + } + } + } + + table.Rows.Add(dataRow); + } + } + /*} + catch (Exception ex) + { + Console.WriteLine("文件内容格式不对!\n\n存在空内容或者列名相同\n\n请重新选择 {0}", ex.StackTrace); + }*/ + return table; + } + + private static int GetSheetRowCount(ISheet sheet) + { + int maxCellCount = 0; + IRow row; + for (int r = 0; r < sheet.LastRowNum; r++) + { + row = sheet.GetRow(r); + if (row != null && row.LastCellNum > maxCellCount) + { + maxCellCount = row.LastCellNum; + } + } + + return maxCellCount; + } + + private static ISheet FillSheetMergedCells(ISheet sheet, int headerMergeRange) + { + Console.WriteLine("=====================sheet: " + sheet.SheetName.ToString()); + int maxCellCount = GetSheetRowCount(sheet); + + MessageBoxResult sheetIgnoreEmptyRowResult = MessageBoxResult.None; + + // method 2 + List mgs = sheet.MergedRegions; + foreach(NPOI.SS.Util.CellRangeAddress cra in mgs) + { + //Console.WriteLine("get a merge region:" + cra.NumberOfCells.ToString()); + //Console.WriteLine("merge region value: " + cra.FormatAsString()); + + for (int c = cra.FirstColumn; c <= cra.LastColumn; c++) + { + for (int r = cra.FirstRow; r <= cra.LastRow; r++) + { + ICell cell = sheet.GetRow(r).GetCell(c); + if(cell != null) + { + cell.SetCellValue(sheet.GetRow(cra.FirstRow).GetCell(cra.FirstColumn).ToString()); + } + + } + } + } + + int emptyCellCount = 0; + + for (int r = 0; r < sheet.LastRowNum; r++) + { + IRow row = sheet.GetRow(r); + + if (row == null) + { + row = sheet.CreateRow(r); + } + + if (row != null) + { + for (int c = 0; c < maxCellCount; c++) + { + ICell cell = row.GetCell(c); + if (cell == null) + { + + cell = row.CreateCell(c); + } + + if (cell != null) + { + if (string.IsNullOrEmpty(cell.ToString())) + { + if (c == 0 && sheetIgnoreEmptyRowResult == MessageBoxResult.None) + { + emptyCellCount++; + if (emptyCellCount >= 5) + { + if(Properties.Settings.Default.ignoreEmptyRow == true) + { + return sheet; + } + else + { + var msgProperties = new WpfMessageBoxProperties() + { + Button = MessageBoxButton.OKCancel, + ButtonOkText = "是(忽略)", + CheckBoxText = "后面都按此处理", + Image = MessageBoxImage.Exclamation, + Header = "表格格式不规范", + IsCheckBoxChecked = Properties.Settings.Default.ignoreEmptyRow, + IsCheckBoxVisible = true, + IsTextBoxVisible = false, + Text = "发现这个表格连续5个行首为空, 是否忽略余下部分", + Title = "表格格式不规范", + }; + sheetIgnoreEmptyRowResult = WpfMessageBox.Show(ref msgProperties); + //Console.WriteLine(result.ToString()); + bool checkBoxChecked = msgProperties.IsCheckBoxChecked; + //Console.WriteLine(checkBoxChecked.ToString()); + Properties.Settings.Default.ignoreEmptyRow = checkBoxChecked; + Properties.Settings.Default.Save(); + + if (sheetIgnoreEmptyRowResult == MessageBoxResult.OK) + { + return sheet; + } + } + } + } + + cell.SetCellValue(string.Format("EC r{0} c{1}", r, c)); + } + } + } + } + + } + return sheet; + } + + #endregion + + #region 公共导出方法 + + /// + /// 由DataSet导出Excel + /// + /// 要导出数据的DataTable + /// Excel工作表 + public static string ExportToExcel(DataSet sourceDs, string filePath) + { + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + + for (int i = 0; i < sourceDs.Tables.Count; i++) + { + DataTable table = sourceDs.Tables[i]; + string sheetName = "result" + i.ToString(); + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + // handling header. + foreach (DataColumn column in table.Columns) + { + ICell cell = headerRow.CreateCell(column.Ordinal); + cell.SetCellValue(column.ColumnName); + cell.CellStyle = cellStyle; + } + + // handling value. + int rowIndex = 1; + + foreach (DataRow row in table.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + + foreach (DataColumn column in table.Columns) + { + dataRow.CreateCell(column.Ordinal).SetCellValue((row[column] ?? "").ToString()); + } + + rowIndex++; + } + } + + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + workbook = null; + + return filePath; + + } + + + /// + /// 由DataTable导出Excel + /// + /// 要导出数据的DataTable + /// Excel工作表 + public static string ExportToExcel(DataTable sourceTable, string sheetName, string filePath) + { + if (sourceTable.Rows.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + // handling header. + foreach (DataColumn column in sourceTable.Columns) + { + ICell headerCell = headerRow.CreateCell(column.Ordinal); + headerCell.SetCellValue(column.ColumnName); + headerCell.CellStyle = cellStyle; + } + + // handling value. + int rowIndex = 1; + + foreach (DataRow row in sourceTable.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + + foreach (DataColumn column in sourceTable.Columns) + { + dataRow.CreateCell(column.Ordinal).SetCellValue((row[column] ?? "").ToString()); + } + + rowIndex++; + } + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + /// + /// 由List导出Excel + /// + /// 类型 + /// 在导出的List + /// sheet名称 + /// + public static string ExportToExcel(List data, IList> headerNameList, string sheetName, string filePath) where T : class + { + if (data.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + ISheet sheet = workbook.CreateSheet(sheetName); + IRow headerRow = sheet.CreateRow(0); + + for (int i = 0; i < headerNameList.Count; i++) + { + ICell cell = headerRow.CreateCell(i); + cell.SetCellValue(headerNameList[i].Value); + cell.CellStyle = cellStyle; + } + + Type t = typeof(T); + int rowIndex = 1; + foreach (T item in data) + { + IRow dataRow = sheet.CreateRow(rowIndex); + for (int n = 0; n < headerNameList.Count; n++) + { + object pValue = t.GetProperty(headerNameList[n].Key).GetValue(item, null); + dataRow.CreateCell(n).SetCellValue((pValue ?? "").ToString()); + } + rowIndex++; + } + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + /// + /// 由DataGridView导出 + /// + /// + /// + /// + /// + public static string ExportToExcel(DataGridView grid, string sheetName, string filePath) + { + if (grid.Rows.Count <= 0) return null; + + if (string.IsNullOrEmpty(filePath)) + { + return filePath; + } + + if (string.IsNullOrEmpty(filePath)) return null; + + bool isCompatible = GetIsCompatible(filePath); + + IWorkbook workbook = CreateWorkbook(isCompatible); + ICellStyle cellStyle = GetCellStyle(workbook); + ISheet sheet = workbook.CreateSheet(sheetName); + + IRow headerRow = sheet.CreateRow(0); + + for (int i = 0; i < grid.Columns.Count; i++) + { + ICell cell = headerRow.CreateCell(i); + cell.SetCellValue(grid.Columns[i].Name); + cell.CellStyle = cellStyle; + } + + int rowIndex = 1; + foreach (DataGridViewRow row in grid.Rows) + { + IRow dataRow = sheet.CreateRow(rowIndex); + for (int n = 0; n < grid.Columns.Count; n++) + { + dataRow.CreateCell(n).SetCellValue((row.Cells[n].Value ?? "").ToString()); + } + rowIndex++; + } + + FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite); + workbook.Write(fs); + fs.Dispose(); + + sheet = null; + headerRow = null; + workbook = null; + + return filePath; + } + + #endregion + + #region 公共服务方法 + + public static List GetSheetNames(string filePath) + { + List sheetNames = new List(); + + bool isCompatible; + IWorkbook wb; + FileStream stream = null; + + try + { + + stream = System.IO.File.OpenRead(filePath); + isCompatible = GetIsCompatible(filePath); + wb = CreateWorkbook(isCompatible, stream); + + for (int i = 0; i < wb.NumberOfSheets; i++) + { + string sn = wb.GetSheetName(i); + sheetNames.Add(sn); + } + + stream.Close(); + } + catch + { + System.Windows.Forms.MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + finally + { + if (stream != null) + { + stream.Close(); + } + + } + + + return sheetNames; + } + + public static List GetSheetNames(IWorkbook wb) + { + List sheetNames = new List(); + + for (int i = 0; i < wb.NumberOfSheets; i++) + { + sheetNames.Add(wb.GetSheetAt(i).SheetName); + } + + return sheetNames; + } + + + #endregion + + #region 公共导入方法 + + /// + /// 由Excel导入DataTable + /// + /// Excel文件流 + /// Excel工作表名称 + /// Excel表头行索引 + /// 是否为兼容模式 + /// DataTable + public static DataTable ImportFromExcel(Stream excelFileStream, string sheetName, int headerRowIndex, bool isCompatible) + { + IWorkbook workbook = CreateWorkbook(isCompatible, excelFileStream); + ISheet sheet = null; + int sheetIndex = -1; + if (int.TryParse(sheetName, out sheetIndex)) + { + sheet = workbook.GetSheetAt(sheetIndex); + } + else + { + sheet = workbook.GetSheet(sheetName); + } + + DataTable table = GetDataTableFromSheet(sheet, headerRowIndex); + + excelFileStream.Close(); + workbook = null; + sheet = null; + return table; + } + + /// + /// 由Excel导入DataTable + /// + /// Excel文件路径,为物理路径。 + /// Excel工作表名称 + /// Excel表头行索引 + /// DataTable + public static DataTable ImportFromExcel(string excelFilePath, string sheetName, int headerRowIndex) + { + FileStream stream = null; + try + { + stream = System.IO.File.OpenRead(excelFilePath); + bool isCompatible = GetIsCompatible(excelFilePath); + return ImportFromExcel(stream, sheetName, headerRowIndex, isCompatible); + + } + catch + { + System.Windows.Forms.MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + DataTable DT = new DataTable(); + return DT; + + } + finally + { + if(stream != null) + { + stream.Close(); + } + + } + + } + + /// + /// 由Excel导入DataSet,如果有多个工作表,则导入多个DataTable + /// + /// Excel文件流 + /// Excel表头行索引 + /// 是否为兼容模式 + /// DataSet + public static DataSet ImportFromExcel(Stream excelFileStream, int headerRowIndex, bool isCompatible) + { + DataSet ds = new DataSet(); + IWorkbook workbook = CreateWorkbook(isCompatible, excelFileStream); + for (int i = 0; i < workbook.NumberOfSheets; i++) + { + ISheet sheet = workbook.GetSheetAt(i); + DataTable table = GetDataTableFromSheet(sheet, headerRowIndex); + ds.Tables.Add(table); + } + + excelFileStream.Close(); + workbook = null; + + return ds; + } + + /// + /// 由Excel导入DataSet,如果有多个工作表,则导入多个DataTable + /// + /// Excel文件路径,为物理路径。 + /// Excel表头行索引 + /// DataSet + public static DataSet ImportFromExcel(string excelFilePath, int headerRowIndex) + { + FileStream stream = null; + try + { + stream = System.IO.File.OpenRead(excelFilePath); + + bool isCompatible = GetIsCompatible(excelFilePath); + return ImportFromExcel(stream, headerRowIndex, isCompatible); + } + catch + { + System.Windows.MessageBox.Show("请关闭文件,再导入!", "提示", (MessageBoxButton)MessageBoxButtons.OK, (MessageBoxImage)MessageBoxIcon.Warning); + DataSet ds = new DataSet(); + return ds; + } + finally + { + if(stream != null) + { + stream.Close(); + } + } + } + + #endregion + + #region 公共转换方法 + + /// + /// 将Excel的列索引转换为列名,列索引从0开始,列名从A开始。如第0列为A,第1列为B... + /// + /// 列索引 + /// 列名,如第0列为A,第1列为B... + public static string ConvertColumnIndexToColumnName(int index) + { + index = index + 1; + int system = 26; + char[] digArray = new char[100]; + int i = 0; + while (index > 0) + { + int mod = index % system; + if (mod == 0) mod = system; + digArray[i++] = (char)(mod - 1 + 'A'); + index = (index - 1) / 26; + } + StringBuilder sb = new StringBuilder(i); + for (int j = i - 1; j >= 0; j--) + { + sb.Append(digArray[j]); + } + return sb.ToString(); + } + + + /// + /// 转化日期 + /// + /// 日期 + /// + public static DateTime ConvertDate(object date) + { + string dtStr = (date ?? "").ToString(); + + DateTime dt = new DateTime(); + + if (DateTime.TryParse(dtStr, out dt)) + { + return dt; + } + + try + { + string spStr = ""; + if (dtStr.Contains("-")) + { + spStr = "-"; + } + else if (dtStr.Contains("/")) + { + spStr = "/"; + } + string[] time = dtStr.Split(spStr.ToCharArray()); + int year = Convert.ToInt32(time[2]); + int month = Convert.ToInt32(time[0]); + int day = Convert.ToInt32(time[1]); + string years = Convert.ToString(year); + string months = Convert.ToString(month); + string days = Convert.ToString(day); + if (months.Length == 4) + { + dt = Convert.ToDateTime(date); + } + else + { + string rq = ""; + if (years.Length == 1) + { + years = "0" + years; + } + if (months.Length == 1) + { + months = "0" + months; + } + if (days.Length == 1) + { + days = "0" + days; + } + rq = "20" + years + "-" + months + "-" + days; + dt = Convert.ToDateTime(rq); + } + } + catch + { + throw new Exception("日期格式不正确,转换日期失败!"); + } + return dt; + } + + /// + /// 转化数字 + /// + /// 数字字符串 + /// + public static decimal ConvertDecimal(object d) + { + string dStr = (d ?? "").ToString(); + decimal result = 0; + if (decimal.TryParse(dStr, out result)) + { + return result; + } + else + { + throw new Exception("数字格式不正确,转换数字失败!"); + } + + } + + #endregion + + #region 数值转换string + private static string GetCellValue(ICell cell) + { + /* + * if (cell == null) + return string.Empty; + switch (cell.CellType) + { + case CellType.Blank: //空数据类型 这里类型注意一下,不同版本NPOI大小写可能不一样,有的版本是Blank(首字母大写) + return string.Empty; + case CellType.Boolean: //bool类型 + return cell.BooleanCellValue.ToString(); + case CellType.Error: + return cell.ErrorCellValue.ToString(); + case CellType.Numeric: //数字类型 + if (HSSFDateUtil.IsCellDateFormatted(cell))//日期类型 + { + return cell.DateCellValue.ToString(); + } + else //其它数字 + { + return cell.NumericCellValue.ToString(); + } + case CellType.Unknown: //无法识别类型 + default: //默认类型 + return cell.ToString();// + case CellType.String: //string 类型 + return cell.StringCellValue; + case CellType.Formula: //带公式类型 + try + { + HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook); + e.EvaluateInCell(cell); + return cell.ToString(); + } + catch + { + return cell.NumericCellValue.ToString(); + } + }*/ + //Console.WriteLine(cell.Sheet.SheetName + " row=" + cell.Row.ToString() + " col=" + cell.ColumnIndex.ToString()); + + + + + if (cell == null) + { + //Console.WriteLine("Empty Cell"); + return "Empty Cell"; + } + else + { + if (cell.IsMergedCell) + { + //Console.WriteLine("we find a merged cell"); + } + + //Console.WriteLine(cell.ToString()); + return cell.ToString(); + } + } + #endregion + } +} diff --git a/ExcelToChart/ExcelToChart.csproj b/ExcelToChart/ExcelToChart.csproj index bf183f3faa46953ed575e45865f4b0abd664b140..17e1de31e28b05f2185b4f0c25f2dd43964e44e6 100644 --- a/ExcelToChart/ExcelToChart.csproj +++ b/ExcelToChart/ExcelToChart.csproj @@ -8,12 +8,28 @@ WinExe ExcelToChart ExcelToChart - v4.0 + v4.5 512 true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + - AnyCPU + x86 true full false @@ -21,6 +37,8 @@ DEBUG;TRACE prompt 4 + true + false AnyCPU @@ -30,16 +48,26 @@ TRACE prompt 4 + false - - ..\MakeReport\packages\BouncyCastle.1.8.9\lib\BouncyCastle.Crypto.dll + + ..\MakeReport\packages\Portable.BouncyCastle.1.8.6\lib\net40\BouncyCastle.Crypto.dll + + + ..\MakeReport\packages\SharpZipLib.1.2.0\lib\net45\ICSharpCode.SharpZipLib.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.dll + + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OOXML.dll - - ..\MakeReport\packages\GemBox.Spreadsheet.47.0.1230\lib\net35\GemBox.Spreadsheet.dll + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OpenXml4Net.dll - - ..\MakeReport\packages\GemBox.Spreadsheet.WinFormsUtilities.47.0.1230\lib\net35\GemBox.Spreadsheet.WinFormsUtilities.dll + + ..\MakeReport\packages\NPOI.2.5.3\lib\net45\NPOI.OpenXmlFormats.dll @@ -57,9 +85,16 @@ + + ..\MakeReport\packages\ToggleSwitch.Net5.2.0.0\lib\net5.0-windows7.0\ToggleSwitch.dll + + + ..\MakeReport\packages\WpfMessageBox.1.2.0\lib\net40-client\WpfMessageBox.dll + + Form @@ -72,23 +107,73 @@ FormHelpRegex.cs + + Form + + + FormProgressBar.cs + Form Form_Chart.cs + + Form + + + Form_CombinedSheet.cs + + + Form + + + Form_DateFormat.cs + + + Form + + + Form_SelectYearMonth.cs + + + Form + + + Form_SheetSelect.cs + + + + + Form + Form1.cs FormHelpRegex.cs + + FormProgressBar.cs + Form_Chart.cs + + Form_CombinedSheet.cs + + + Form_DateFormat.cs + + + Form_SelectYearMonth.cs + + + Form_SheetSelect.cs + ResXFileCodeGenerator Resources.Designer.cs @@ -97,6 +182,7 @@ True Resources.resx + True @@ -110,5 +196,41 @@ True + + + {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} + 2 + 4 + 0 + primary + False + True + + + {00020813-0000-0000-C000-000000000046} + 1 + 6 + 0 + primary + False + True + + + {0002E157-0000-0000-C000-000000000046} + 5 + 3 + 0 + primary + False + True + + + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/ExcelToChart/Form1.Designer.cs b/ExcelToChart/Form1.Designer.cs index 060038b27c844b909655c0fef78143bb9311ffe1..993164a85b5500a9b2a7ec09a1a46795082fba5c 100644 --- a/ExcelToChart/Form1.Designer.cs +++ b/ExcelToChart/Form1.Designer.cs @@ -29,74 +29,135 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.buttonLoadFile = new System.Windows.Forms.Button(); - this.buttonSave = new System.Windows.Forms.Button(); + this.button_selectFile = new System.Windows.Forms.Button(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.textBox_filePathLastTime = new System.Windows.Forms.TextBox(); - this.contextMenuStrip_rowDel = new System.Windows.Forms.ContextMenuStrip(this.components); + this.contextMenuStrip_RowOps = new System.Windows.Forms.ContextMenuStrip(this.components); + this.ToolStripMenuItem_SetAsHeader = new System.Windows.Forms.ToolStripMenuItem(); this.rowDelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.contextMenuStrip_clmDel = new System.Windows.Forms.ContextMenuStrip(this.components); + this.ToolStripMenuItem_deleteAllRowsBelow = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_displayRowColor = new System.Windows.Forms.ToolStripMenuItem(); + this.contextMenuStrip_ColumnOps = new System.Windows.Forms.ContextMenuStrip(this.components); this.ToolStripMenuItem_delCurrentColumn = new System.Windows.Forms.ToolStripMenuItem(); this.ToolStripMenuItem_delAllColumnsRightside = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_modify_column_name = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_setDateColumn = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_setNumberColumn = new System.Windows.Forms.ToolStripMenuItem(); this.textBox_regex_filter = new System.Windows.Forms.TextBox(); this.button_select_rows_by_regex = new System.Windows.Forms.Button(); this.button_deselect_rows_by_regex = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.label1 = new System.Windows.Forms.Label(); + this.button_selete_row_tag_as_deleted = new System.Windows.Forms.Button(); + this.button_applyRowRuleToAllSheet = new System.Windows.Forms.Button(); + this.button_disselect_row_all = new System.Windows.Forms.Button(); + this.button_select_row_all = new System.Windows.Forms.Button(); + this.button_getContentAbove = new System.Windows.Forms.Button(); this.button_delete_selected_rows = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); this.groupBox2 = new System.Windows.Forms.GroupBox(); - this.button_show_line_chart = new System.Windows.Forms.Button(); + this.button_filter_preview_enable = new System.Windows.Forms.Button(); this.button_show_Histogram = new System.Windows.Forms.Button(); + this.button_show_line_chart = new System.Windows.Forms.Button(); + this.button_filter_preview_disable = new System.Windows.Forms.Button(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_OpenFile = new System.Windows.Forms.ToolStripMenuItem(); + this.保存ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.另存为ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.ToolStripMenuItem_CloseMainForm = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripComboBox1 = new System.Windows.Forms.ToolStripComboBox(); + this.toolStripTextBox1 = new System.Windows.Forms.ToolStripTextBox(); this.编辑ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.选项ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.帮助ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.帮助ToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.关于ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.开发中ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.opentestinteropexcelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.formProgressToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.formDatePreviewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.testPartialClassToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip_tabcontrol = new System.Windows.Forms.ContextMenuStrip(this.components); this.ToolStripMenuItem_tablcontrol_remove_page = new System.Windows.Forms.ToolStripMenuItem(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.button_FormatFirstColumn = new System.Windows.Forms.Button(); + this.button_applyColumnRuleToAllSheet = new System.Windows.Forms.Button(); + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton(); + this.cToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.bToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.aToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSplitButton1 = new System.Windows.Forms.ToolStripSplitButton(); + this.cToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.bToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.aToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.groupBox5 = new System.Windows.Forms.GroupBox(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.testFormCombinedSheetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); - this.contextMenuStrip_rowDel.SuspendLayout(); - this.contextMenuStrip_clmDel.SuspendLayout(); + this.contextMenuStrip_RowOps.SuspendLayout(); + this.contextMenuStrip_ColumnOps.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.contextMenuStrip_tabcontrol.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.groupBox4.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.groupBox5.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.SuspendLayout(); // // dataGridView1 // this.dataGridView1.AllowUserToOrderColumns = true; + this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView1.Location = new System.Drawing.Point(12, 99); + this.dataGridView1.Location = new System.Drawing.Point(12, 53); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.RowTemplate.Height = 23; - this.dataGridView1.Size = new System.Drawing.Size(511, 246); + this.dataGridView1.Size = new System.Drawing.Size(603, 178); this.dataGridView1.TabIndex = 0; + this.dataGridView1.DataSourceChanged += new System.EventHandler(this.dataGridView1_DataSourceChanged); this.dataGridView1.CellMouseUp += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseUp); + this.dataGridView1.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridView1_SortCompare); + this.dataGridView1.Sorted += new System.EventHandler(this.dataGridView1_Sorted); // // buttonLoadFile // - this.buttonLoadFile.Location = new System.Drawing.Point(135, 67); + this.buttonLoadFile.Location = new System.Drawing.Point(551, 16); this.buttonLoadFile.Name = "buttonLoadFile"; - this.buttonLoadFile.Size = new System.Drawing.Size(184, 26); + this.buttonLoadFile.Size = new System.Drawing.Size(114, 26); this.buttonLoadFile.TabIndex = 1; this.buttonLoadFile.Text = "LoadFile"; this.buttonLoadFile.UseVisualStyleBackColor = true; this.buttonLoadFile.Click += new System.EventHandler(this.buttonLoadFile_Click); // - // buttonSave + // button_selectFile // - this.buttonSave.Location = new System.Drawing.Point(457, 67); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(174, 26); - this.buttonSave.TabIndex = 2; - this.buttonSave.Text = "Save"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + this.button_selectFile.Location = new System.Drawing.Point(508, 16); + this.button_selectFile.Name = "button_selectFile"; + this.button_selectFile.Size = new System.Drawing.Size(37, 26); + this.button_selectFile.TabIndex = 2; + this.button_selectFile.Text = "..."; + this.button_selectFile.UseVisualStyleBackColor = true; + this.button_selectFile.Click += new System.EventHandler(this.buttonSelectFile_Click); // // openFileDialog1 // @@ -104,60 +165,112 @@ // // tabControl1 // - this.tabControl1.Location = new System.Drawing.Point(12, 351); + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.tabControl1.Location = new System.Drawing.Point(12, 27); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(511, 195); + this.tabControl1.Size = new System.Drawing.Size(796, 20); this.tabControl1.TabIndex = 3; this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged); this.tabControl1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.tabControl1_MouseClick); + this.tabControl1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.tabControl1_MouseMove); // // textBox_filePathLastTime // - this.textBox_filePathLastTime.Location = new System.Drawing.Point(135, 30); + this.textBox_filePathLastTime.Location = new System.Drawing.Point(6, 20); this.textBox_filePathLastTime.Name = "textBox_filePathLastTime"; this.textBox_filePathLastTime.Size = new System.Drawing.Size(496, 21); this.textBox_filePathLastTime.TabIndex = 4; + this.textBox_filePathLastTime.TextChanged += new System.EventHandler(this.textBox_filePathLastTime_TextChanged); + // + // contextMenuStrip_RowOps // - // contextMenuStrip_rowDel + this.contextMenuStrip_RowOps.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem_SetAsHeader, + this.rowDelToolStripMenuItem, + this.ToolStripMenuItem_deleteAllRowsBelow, + this.ToolStripMenuItem_displayRowColor}); + this.contextMenuStrip_RowOps.Name = "contextMenuStrip_rowDel"; + this.contextMenuStrip_RowOps.Size = new System.Drawing.Size(218, 92); // - this.contextMenuStrip_rowDel.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.rowDelToolStripMenuItem}); - this.contextMenuStrip_rowDel.Name = "contextMenuStrip_rowDel"; - this.contextMenuStrip_rowDel.Size = new System.Drawing.Size(114, 26); + // ToolStripMenuItem_SetAsHeader + // + this.ToolStripMenuItem_SetAsHeader.Name = "ToolStripMenuItem_SetAsHeader"; + this.ToolStripMenuItem_SetAsHeader.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_SetAsHeader.Text = "提升为标题行"; + this.ToolStripMenuItem_SetAsHeader.Click += new System.EventHandler(this.ToolStripMenuItem_SetAsHeader_Click); // // rowDelToolStripMenuItem // this.rowDelToolStripMenuItem.Name = "rowDelToolStripMenuItem"; - this.rowDelToolStripMenuItem.Size = new System.Drawing.Size(113, 22); - this.rowDelToolStripMenuItem.Text = "删除行"; - this.rowDelToolStripMenuItem.Click += new System.EventHandler(this.rowDelToolStripMenuItem_Click); + this.rowDelToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.rowDelToolStripMenuItem.Text = "切换选中行删除标记"; + this.rowDelToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_deleteCurrentRow_Click); + // + // ToolStripMenuItem_deleteAllRowsBelow + // + this.ToolStripMenuItem_deleteAllRowsBelow.Name = "ToolStripMenuItem_deleteAllRowsBelow"; + this.ToolStripMenuItem_deleteAllRowsBelow.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_deleteAllRowsBelow.Text = "切换以下所有行删除标记"; + this.ToolStripMenuItem_deleteAllRowsBelow.Click += new System.EventHandler(this.ToolStripMenuItem_deleteAllRowsBelow_Click); + // + // ToolStripMenuItem_displayRowColor + // + this.ToolStripMenuItem_displayRowColor.Name = "ToolStripMenuItem_displayRowColor"; + this.ToolStripMenuItem_displayRowColor.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_displayRowColor.Text = "打印行颜色"; + this.ToolStripMenuItem_displayRowColor.Click += new System.EventHandler(this.ToolStripMenuItem_displayRowColor_Click); // - // contextMenuStrip_clmDel + // contextMenuStrip_ColumnOps // - this.contextMenuStrip_clmDel.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.contextMenuStrip_ColumnOps.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolStripMenuItem_delCurrentColumn, - this.ToolStripMenuItem_delAllColumnsRightside}); - this.contextMenuStrip_clmDel.Name = "contextMenuStrip_clmDel"; - this.contextMenuStrip_clmDel.Size = new System.Drawing.Size(166, 48); + this.ToolStripMenuItem_delAllColumnsRightside, + this.ToolStripMenuItem_modify_column_name, + this.ToolStripMenuItem_setDateColumn, + this.ToolStripMenuItem_setNumberColumn}); + this.contextMenuStrip_ColumnOps.Name = "contextMenuStrip_clmDel"; + this.contextMenuStrip_ColumnOps.Size = new System.Drawing.Size(218, 114); // // ToolStripMenuItem_delCurrentColumn // this.ToolStripMenuItem_delCurrentColumn.Name = "ToolStripMenuItem_delCurrentColumn"; - this.ToolStripMenuItem_delCurrentColumn.Size = new System.Drawing.Size(165, 22); - this.ToolStripMenuItem_delCurrentColumn.Text = "删除列"; + this.ToolStripMenuItem_delCurrentColumn.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_delCurrentColumn.Text = "切换列删除标记"; this.ToolStripMenuItem_delCurrentColumn.Click += new System.EventHandler(this.ToolStripMenuItem_delCurrentColumn_Click); // // ToolStripMenuItem_delAllColumnsRightside // this.ToolStripMenuItem_delAllColumnsRightside.Name = "ToolStripMenuItem_delAllColumnsRightside"; - this.ToolStripMenuItem_delAllColumnsRightside.Size = new System.Drawing.Size(165, 22); - this.ToolStripMenuItem_delAllColumnsRightside.Text = "删除右侧所有列"; + this.ToolStripMenuItem_delAllColumnsRightside.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_delAllColumnsRightside.Text = "切换右侧所有列删除标记"; this.ToolStripMenuItem_delAllColumnsRightside.Click += new System.EventHandler(this.ToolStripMenuItem_delAllColumnsRightside_Click); // + // ToolStripMenuItem_modify_column_name + // + this.ToolStripMenuItem_modify_column_name.Name = "ToolStripMenuItem_modify_column_name"; + this.ToolStripMenuItem_modify_column_name.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_modify_column_name.Text = "修改列名"; + this.ToolStripMenuItem_modify_column_name.Click += new System.EventHandler(this.ToolStripMenuItem_modify_column_name_Click); + // + // ToolStripMenuItem_setDateColumn + // + this.ToolStripMenuItem_setDateColumn.Name = "ToolStripMenuItem_setDateColumn"; + this.ToolStripMenuItem_setDateColumn.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_setDateColumn.Text = "设为日期列"; + this.ToolStripMenuItem_setDateColumn.Click += new System.EventHandler(this.ToolStripMenuItem_setDateColumn_Click); + // + // ToolStripMenuItem_setNumberColumn + // + this.ToolStripMenuItem_setNumberColumn.Name = "ToolStripMenuItem_setNumberColumn"; + this.ToolStripMenuItem_setNumberColumn.Size = new System.Drawing.Size(217, 22); + this.ToolStripMenuItem_setNumberColumn.Text = "设为产量列"; + this.ToolStripMenuItem_setNumberColumn.Click += new System.EventHandler(this.ToolStripMenuItem_setNumberColumn_Click); + // // textBox_regex_filter // - this.textBox_regex_filter.Location = new System.Drawing.Point(36, 79); + this.textBox_regex_filter.Location = new System.Drawing.Point(125, 55); this.textBox_regex_filter.Name = "textBox_regex_filter"; this.textBox_regex_filter.Size = new System.Drawing.Size(90, 21); this.textBox_regex_filter.TabIndex = 7; @@ -165,7 +278,7 @@ // // button_select_rows_by_regex // - this.button_select_rows_by_regex.Location = new System.Drawing.Point(132, 77); + this.button_select_rows_by_regex.Location = new System.Drawing.Point(221, 53); this.button_select_rows_by_regex.Name = "button_select_rows_by_regex"; this.button_select_rows_by_regex.Size = new System.Drawing.Size(40, 23); this.button_select_rows_by_regex.TabIndex = 8; @@ -175,7 +288,7 @@ // // button_deselect_rows_by_regex // - this.button_deselect_rows_by_regex.Location = new System.Drawing.Point(178, 77); + this.button_deselect_rows_by_regex.Location = new System.Drawing.Point(140, 21); this.button_deselect_rows_by_regex.Name = "button_deselect_rows_by_regex"; this.button_deselect_rows_by_regex.Size = new System.Drawing.Size(40, 23); this.button_deselect_rows_by_regex.TabIndex = 9; @@ -185,51 +298,131 @@ // // groupBox1 // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.groupBox1.Controls.Add(this.button_selete_row_tag_as_deleted); + this.groupBox1.Controls.Add(this.button_applyRowRuleToAllSheet); + this.groupBox1.Controls.Add(this.button_disselect_row_all); + this.groupBox1.Controls.Add(this.button_select_row_all); + this.groupBox1.Controls.Add(this.button_getContentAbove); this.groupBox1.Controls.Add(this.button_delete_selected_rows); this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.textBox_regex_filter); this.groupBox1.Controls.Add(this.button_deselect_rows_by_regex); this.groupBox1.Controls.Add(this.button_select_rows_by_regex); - this.groupBox1.Location = new System.Drawing.Point(544, 99); + this.groupBox1.Location = new System.Drawing.Point(12, 308); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(264, 166); + this.groupBox1.Size = new System.Drawing.Size(279, 230); this.groupBox1.TabIndex = 10; this.groupBox1.TabStop = false; - this.groupBox1.Text = "groupBox1"; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(7, 79); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(29, 12); - this.label1.TabIndex = 10; - this.label1.Text = "正则"; + this.groupBox1.Text = "行操作"; + // + // button_selete_row_tag_as_deleted + // + this.button_selete_row_tag_as_deleted.Location = new System.Drawing.Point(6, 81); + this.button_selete_row_tag_as_deleted.Name = "button_selete_row_tag_as_deleted"; + this.button_selete_row_tag_as_deleted.Size = new System.Drawing.Size(85, 23); + this.button_selete_row_tag_as_deleted.TabIndex = 15; + this.button_selete_row_tag_as_deleted.Text = "选中删除标记"; + this.button_selete_row_tag_as_deleted.UseVisualStyleBackColor = true; + this.button_selete_row_tag_as_deleted.Click += new System.EventHandler(this.button_selete_row_tag_as_deleted_Click); + // + // button_applyRowRuleToAllSheet + // + this.button_applyRowRuleToAllSheet.Location = new System.Drawing.Point(6, 191); + this.button_applyRowRuleToAllSheet.Name = "button_applyRowRuleToAllSheet"; + this.button_applyRowRuleToAllSheet.Size = new System.Drawing.Size(209, 23); + this.button_applyRowRuleToAllSheet.TabIndex = 15; + this.button_applyRowRuleToAllSheet.Text = "把行删除规则应用到所有表"; + this.button_applyRowRuleToAllSheet.UseVisualStyleBackColor = true; + this.button_applyRowRuleToAllSheet.Click += new System.EventHandler(this.button_applyRowRuleToAllSheet_Click); + // + // button_disselect_row_all + // + this.button_disselect_row_all.Location = new System.Drawing.Point(84, 21); + this.button_disselect_row_all.Name = "button_disselect_row_all"; + this.button_disselect_row_all.Size = new System.Drawing.Size(50, 23); + this.button_disselect_row_all.TabIndex = 14; + this.button_disselect_row_all.Text = "不选"; + this.button_disselect_row_all.UseVisualStyleBackColor = true; + this.button_disselect_row_all.Click += new System.EventHandler(this.button_disselect_row_all_Click); + // + // button_select_row_all + // + this.button_select_row_all.Location = new System.Drawing.Point(27, 21); + this.button_select_row_all.Name = "button_select_row_all"; + this.button_select_row_all.Size = new System.Drawing.Size(51, 23); + this.button_select_row_all.TabIndex = 13; + this.button_select_row_all.Text = "全选"; + this.button_select_row_all.UseVisualStyleBackColor = true; + this.button_select_row_all.Click += new System.EventHandler(this.button_select_row_all_Click); + // + // button_getContentAbove + // + this.button_getContentAbove.Location = new System.Drawing.Point(6, 162); + this.button_getContentAbove.Name = "button_getContentAbove"; + this.button_getContentAbove.Size = new System.Drawing.Size(164, 23); + this.button_getContentAbove.TabIndex = 12; + this.button_getContentAbove.Text = "首列保留单元从上方取值"; + this.button_getContentAbove.UseVisualStyleBackColor = true; + this.button_getContentAbove.Click += new System.EventHandler(this.button_getContentAbove_Click); // // button_delete_selected_rows // - this.button_delete_selected_rows.Location = new System.Drawing.Point(178, 118); + this.button_delete_selected_rows.Location = new System.Drawing.Point(6, 132); this.button_delete_selected_rows.Name = "button_delete_selected_rows"; - this.button_delete_selected_rows.Size = new System.Drawing.Size(80, 28); + this.button_delete_selected_rows.Size = new System.Drawing.Size(164, 24); this.button_delete_selected_rows.TabIndex = 11; - this.button_delete_selected_rows.Text = "删除选中行"; + this.button_delete_selected_rows.Text = "切换行删除标记状态"; this.button_delete_selected_rows.UseVisualStyleBackColor = true; this.button_delete_selected_rows.Click += new System.EventHandler(this.button_delete_selected_rows_Click); // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(6, 55); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(95, 12); + this.label1.TabIndex = 10; + this.label1.Text = "首行按Regex选择"; + // // groupBox2 // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.button_filter_preview_enable); this.groupBox2.Controls.Add(this.button_show_Histogram); this.groupBox2.Controls.Add(this.button_show_line_chart); - this.groupBox2.Location = new System.Drawing.Point(544, 272); + this.groupBox2.Controls.Add(this.button_filter_preview_disable); + this.groupBox2.Location = new System.Drawing.Point(566, 308); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(264, 73); + this.groupBox2.Size = new System.Drawing.Size(242, 230); this.groupBox2.TabIndex = 11; this.groupBox2.TabStop = false; - this.groupBox2.Text = "groupBox2"; + this.groupBox2.Text = "图表生成"; + // + // button_filter_preview_enable + // + this.button_filter_preview_enable.Location = new System.Drawing.Point(7, 20); + this.button_filter_preview_enable.Name = "button_filter_preview_enable"; + this.button_filter_preview_enable.Size = new System.Drawing.Size(75, 23); + this.button_filter_preview_enable.TabIndex = 13; + this.button_filter_preview_enable.Text = "预览"; + this.button_filter_preview_enable.UseVisualStyleBackColor = true; + this.button_filter_preview_enable.Click += new System.EventHandler(this.button_filter_preview_enable_Click); + // + // button_show_Histogram + // + this.button_show_Histogram.Location = new System.Drawing.Point(7, 96); + this.button_show_Histogram.Name = "button_show_Histogram"; + this.button_show_Histogram.Size = new System.Drawing.Size(163, 23); + this.button_show_Histogram.TabIndex = 1; + this.button_show_Histogram.Text = "保存当前数据为新Excel文件"; + this.button_show_Histogram.UseVisualStyleBackColor = true; + this.button_show_Histogram.Click += new System.EventHandler(this.button_show_Histogram_Click); // // button_show_line_chart // - this.button_show_line_chart.Location = new System.Drawing.Point(27, 20); + this.button_show_line_chart.Location = new System.Drawing.Point(7, 61); this.button_show_line_chart.Name = "button_show_line_chart"; this.button_show_line_chart.Size = new System.Drawing.Size(75, 23); this.button_show_line_chart.TabIndex = 0; @@ -237,15 +430,15 @@ this.button_show_line_chart.UseVisualStyleBackColor = true; this.button_show_line_chart.Click += new System.EventHandler(this.button_show_line_chart_Click); // - // button_show_Histogram + // button_filter_preview_disable // - this.button_show_Histogram.Location = new System.Drawing.Point(143, 20); - this.button_show_Histogram.Name = "button_show_Histogram"; - this.button_show_Histogram.Size = new System.Drawing.Size(75, 23); - this.button_show_Histogram.TabIndex = 1; - this.button_show_Histogram.Text = "生成柱状图"; - this.button_show_Histogram.UseVisualStyleBackColor = true; - this.button_show_Histogram.Click += new System.EventHandler(this.button_show_Histogram_Click); + this.button_filter_preview_disable.Location = new System.Drawing.Point(95, 20); + this.button_filter_preview_disable.Name = "button_filter_preview_disable"; + this.button_filter_preview_disable.Size = new System.Drawing.Size(75, 23); + this.button_filter_preview_disable.TabIndex = 14; + this.button_filter_preview_disable.Text = "取消预览"; + this.button_filter_preview_disable.UseVisualStyleBackColor = true; + this.button_filter_preview_disable.Click += new System.EventHandler(this.button_filter_preview_disable_Click); // // menuStrip1 // @@ -253,7 +446,8 @@ this.文件ToolStripMenuItem, this.编辑ToolStripMenuItem, this.选项ToolStripMenuItem, - this.帮助ToolStripMenuItem}); + this.帮助ToolStripMenuItem, + this.开发中ToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(820, 24); @@ -262,10 +456,60 @@ // // 文件ToolStripMenuItem // + this.文件ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem_OpenFile, + this.保存ToolStripMenuItem, + this.另存为ToolStripMenuItem, + this.toolStripSeparator1, + this.ToolStripMenuItem_CloseMainForm, + this.toolStripComboBox1, + this.toolStripTextBox1}); this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; this.文件ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); this.文件ToolStripMenuItem.Text = "文件"; // + // ToolStripMenuItem_OpenFile + // + this.ToolStripMenuItem_OpenFile.Name = "ToolStripMenuItem_OpenFile"; + this.ToolStripMenuItem_OpenFile.Size = new System.Drawing.Size(181, 22); + this.ToolStripMenuItem_OpenFile.Text = "打开"; + this.ToolStripMenuItem_OpenFile.Click += new System.EventHandler(this.ToolStripMenuItem_OpenFile_Click); + // + // 保存ToolStripMenuItem + // + this.保存ToolStripMenuItem.Name = "保存ToolStripMenuItem"; + this.保存ToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.保存ToolStripMenuItem.Text = "保存"; + // + // 另存为ToolStripMenuItem + // + this.另存为ToolStripMenuItem.Name = "另存为ToolStripMenuItem"; + this.另存为ToolStripMenuItem.Size = new System.Drawing.Size(181, 22); + this.另存为ToolStripMenuItem.Text = "另存为"; + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(178, 6); + // + // ToolStripMenuItem_CloseMainForm + // + this.ToolStripMenuItem_CloseMainForm.Name = "ToolStripMenuItem_CloseMainForm"; + this.ToolStripMenuItem_CloseMainForm.Size = new System.Drawing.Size(181, 22); + this.ToolStripMenuItem_CloseMainForm.Text = "关闭"; + this.ToolStripMenuItem_CloseMainForm.Click += new System.EventHandler(this.ToolStripMenuItem_CloseMainForm_Click); + // + // toolStripComboBox1 + // + this.toolStripComboBox1.Name = "toolStripComboBox1"; + this.toolStripComboBox1.Size = new System.Drawing.Size(121, 23); + // + // toolStripTextBox1 + // + this.toolStripTextBox1.Font = new System.Drawing.Font("Segoe UI", 9F); + this.toolStripTextBox1.Name = "toolStripTextBox1"; + this.toolStripTextBox1.Size = new System.Drawing.Size(100, 23); + // // 编辑ToolStripMenuItem // this.编辑ToolStripMenuItem.Name = "编辑ToolStripMenuItem"; @@ -290,15 +534,53 @@ // 帮助ToolStripMenuItem1 // this.帮助ToolStripMenuItem1.Name = "帮助ToolStripMenuItem1"; - this.帮助ToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.帮助ToolStripMenuItem1.Size = new System.Drawing.Size(100, 22); this.帮助ToolStripMenuItem1.Text = "帮助"; // // 关于ToolStripMenuItem // this.关于ToolStripMenuItem.Name = "关于ToolStripMenuItem"; - this.关于ToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.关于ToolStripMenuItem.Size = new System.Drawing.Size(100, 22); this.关于ToolStripMenuItem.Text = "关于"; // + // 开发中ToolStripMenuItem + // + this.开发中ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.opentestinteropexcelToolStripMenuItem, + this.formProgressToolStripMenuItem, + this.formDatePreviewToolStripMenuItem, + this.testPartialClassToolStripMenuItem, + this.testFormCombinedSheetToolStripMenuItem}); + this.开发中ToolStripMenuItem.Name = "开发中ToolStripMenuItem"; + this.开发中ToolStripMenuItem.Size = new System.Drawing.Size(58, 20); + this.开发中ToolStripMenuItem.Text = "开发中"; + // + // opentestinteropexcelToolStripMenuItem + // + this.opentestinteropexcelToolStripMenuItem.Name = "opentestinteropexcelToolStripMenuItem"; + this.opentestinteropexcelToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.opentestinteropexcelToolStripMenuItem.Text = "opentest_interop_excel"; + // + // formProgressToolStripMenuItem + // + this.formProgressToolStripMenuItem.Name = "formProgressToolStripMenuItem"; + this.formProgressToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.formProgressToolStripMenuItem.Text = "form progress"; + // + // formDatePreviewToolStripMenuItem + // + this.formDatePreviewToolStripMenuItem.Name = "formDatePreviewToolStripMenuItem"; + this.formDatePreviewToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.formDatePreviewToolStripMenuItem.Text = "Form_DatePreview"; + this.formDatePreviewToolStripMenuItem.Click += new System.EventHandler(this.formDatePreviewToolStripMenuItem_Click); + // + // testPartialClassToolStripMenuItem + // + this.testPartialClassToolStripMenuItem.Name = "testPartialClassToolStripMenuItem"; + this.testPartialClassToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.testPartialClassToolStripMenuItem.Text = "TestPartialClass"; + this.testPartialClassToolStripMenuItem.Click += new System.EventHandler(this.testPartialClassToolStripMenuItem_Click); + // // contextMenuStrip_tabcontrol // this.contextMenuStrip_tabcontrol.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -309,35 +591,245 @@ // ToolStripMenuItem_tablcontrol_remove_page // this.ToolStripMenuItem_tablcontrol_remove_page.Name = "ToolStripMenuItem_tablcontrol_remove_page"; - this.ToolStripMenuItem_tablcontrol_remove_page.Size = new System.Drawing.Size(180, 22); + this.ToolStripMenuItem_tablcontrol_remove_page.Size = new System.Drawing.Size(113, 22); this.ToolStripMenuItem_tablcontrol_remove_page.Text = "删除页"; this.ToolStripMenuItem_tablcontrol_remove_page.Click += new System.EventHandler(this.ToolStripMenuItem_tablcontrol_remove_page_Click); // + // groupBox3 + // + this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox3.Controls.Add(this.textBox_filePathLastTime); + this.groupBox3.Controls.Add(this.buttonLoadFile); + this.groupBox3.Controls.Add(this.button_selectFile); + this.groupBox3.Location = new System.Drawing.Point(12, 237); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Size = new System.Drawing.Size(796, 65); + this.groupBox3.TabIndex = 13; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "groupBox3"; + // + // groupBox4 + // + this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.groupBox4.Controls.Add(this.button_FormatFirstColumn); + this.groupBox4.Controls.Add(this.button_applyColumnRuleToAllSheet); + this.groupBox4.Location = new System.Drawing.Point(297, 308); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Size = new System.Drawing.Size(263, 230); + this.groupBox4.TabIndex = 14; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "页操作"; + // + // button_FormatFirstColumn + // + this.button_FormatFirstColumn.Location = new System.Drawing.Point(24, 21); + this.button_FormatFirstColumn.Name = "button_FormatFirstColumn"; + this.button_FormatFirstColumn.Size = new System.Drawing.Size(209, 23); + this.button_FormatFirstColumn.TabIndex = 17; + this.button_FormatFirstColumn.Text = "尝试将首列变为日期标准化格式"; + this.button_FormatFirstColumn.UseVisualStyleBackColor = true; + this.button_FormatFirstColumn.Click += new System.EventHandler(this.button_FormatFirstColumn_Click); + // + // button_applyColumnRuleToAllSheet + // + this.button_applyColumnRuleToAllSheet.Location = new System.Drawing.Point(24, 186); + this.button_applyColumnRuleToAllSheet.Name = "button_applyColumnRuleToAllSheet"; + this.button_applyColumnRuleToAllSheet.Size = new System.Drawing.Size(209, 28); + this.button_applyColumnRuleToAllSheet.TabIndex = 16; + this.button_applyColumnRuleToAllSheet.Text = "把列删除规则应用到所有表"; + this.button_applyColumnRuleToAllSheet.UseVisualStyleBackColor = true; + this.button_applyColumnRuleToAllSheet.Click += new System.EventHandler(this.button_applyColumnRuleToAllSheet_Click); + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); + this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); + // + // statusStrip1 + // + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripProgressBar1, + this.toolStripStatusLabel1, + this.toolStripStatusLabel2, + this.toolStripDropDownButton1, + this.toolStripSplitButton1}); + this.statusStrip1.Location = new System.Drawing.Point(0, 541); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(820, 22); + this.statusStrip1.TabIndex = 15; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripProgressBar1 + // + this.toolStripProgressBar1.Name = "toolStripProgressBar1"; + this.toolStripProgressBar1.Size = new System.Drawing.Size(100, 16); + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(193, 17); + this.toolStripStatusLabel1.Text = " "; + // + // toolStripStatusLabel2 + // + this.toolStripStatusLabel2.Name = "toolStripStatusLabel2"; + this.toolStripStatusLabel2.Size = new System.Drawing.Size(165, 17); + this.toolStripStatusLabel2.Text = "toolStripStatusLabel_fileName"; + // + // toolStripDropDownButton1 + // + this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.cToolStripMenuItem, + this.bToolStripMenuItem, + this.aToolStripMenuItem}); + this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image"))); + this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 20); + this.toolStripDropDownButton1.Text = "toolStripDropDownButton1"; + // + // cToolStripMenuItem + // + this.cToolStripMenuItem.Name = "cToolStripMenuItem"; + this.cToolStripMenuItem.Size = new System.Drawing.Size(81, 22); + this.cToolStripMenuItem.Text = "c"; + // + // bToolStripMenuItem + // + this.bToolStripMenuItem.Name = "bToolStripMenuItem"; + this.bToolStripMenuItem.Size = new System.Drawing.Size(81, 22); + this.bToolStripMenuItem.Text = "b"; + // + // aToolStripMenuItem + // + this.aToolStripMenuItem.Name = "aToolStripMenuItem"; + this.aToolStripMenuItem.Size = new System.Drawing.Size(81, 22); + this.aToolStripMenuItem.Text = "a"; + // + // toolStripSplitButton1 + // + this.toolStripSplitButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; + this.toolStripSplitButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.cToolStripMenuItem1, + this.bToolStripMenuItem1, + this.aToolStripMenuItem1}); + this.toolStripSplitButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripSplitButton1.Image"))); + this.toolStripSplitButton1.ImageTransparentColor = System.Drawing.Color.Magenta; + this.toolStripSplitButton1.Name = "toolStripSplitButton1"; + this.toolStripSplitButton1.Size = new System.Drawing.Size(32, 20); + this.toolStripSplitButton1.Text = "toolStripSplitButton1"; + // + // cToolStripMenuItem1 + // + this.cToolStripMenuItem1.Name = "cToolStripMenuItem1"; + this.cToolStripMenuItem1.Size = new System.Drawing.Size(81, 22); + this.cToolStripMenuItem1.Text = "c"; + // + // bToolStripMenuItem1 + // + this.bToolStripMenuItem1.Name = "bToolStripMenuItem1"; + this.bToolStripMenuItem1.Size = new System.Drawing.Size(81, 22); + this.bToolStripMenuItem1.Text = "b"; + // + // aToolStripMenuItem1 + // + this.aToolStripMenuItem1.Name = "aToolStripMenuItem1"; + this.aToolStripMenuItem1.Size = new System.Drawing.Size(81, 22); + this.aToolStripMenuItem1.Text = "a"; + // + // groupBox5 + // + this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox5.Controls.Add(this.numericUpDown1); + this.groupBox5.Controls.Add(this.comboBox1); + this.groupBox5.Controls.Add(this.label3); + this.groupBox5.Controls.Add(this.label2); + this.groupBox5.Location = new System.Drawing.Point(621, 54); + this.groupBox5.Name = "groupBox5"; + this.groupBox5.Size = new System.Drawing.Size(187, 177); + this.groupBox5.TabIndex = 16; + this.groupBox5.TabStop = false; + this.groupBox5.Text = "页附加属性"; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(63, 45); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(120, 21); + this.numericUpDown1.TabIndex = 3; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Location = new System.Drawing.Point(63, 18); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(100, 20); + this.comboBox1.TabIndex = 2; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(7, 44); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(41, 12); + this.label3.TabIndex = 1; + this.label3.Text = "数量列"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(7, 21); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 0; + this.label2.Text = "日期列"; + // + // testFormCombinedSheetToolStripMenuItem + // + this.testFormCombinedSheetToolStripMenuItem.Name = "testFormCombinedSheetToolStripMenuItem"; + this.testFormCombinedSheetToolStripMenuItem.Size = new System.Drawing.Size(217, 22); + this.testFormCombinedSheetToolStripMenuItem.Text = "Test_Form_CombinedSheet"; + this.testFormCombinedSheetToolStripMenuItem.Click += new System.EventHandler(this.testFormCombinedSheetToolStripMenuItem_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(820, 563); + this.Controls.Add(this.groupBox5); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.groupBox4); + this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.menuStrip1); - this.Controls.Add(this.textBox_filePathLastTime); this.Controls.Add(this.tabControl1); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.buttonLoadFile); this.Controls.Add(this.dataGridView1); this.MainMenuStrip = this.menuStrip1; this.Name = "Form1"; this.Text = "Form1"; ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); - this.contextMenuStrip_rowDel.ResumeLayout(false); - this.contextMenuStrip_clmDel.ResumeLayout(false); + this.contextMenuStrip_RowOps.ResumeLayout(false); + this.contextMenuStrip_ColumnOps.ResumeLayout(false); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.contextMenuStrip_tabcontrol.ResumeLayout(false); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.groupBox4.ResumeLayout(false); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.groupBox5.ResumeLayout(false); + this.groupBox5.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -347,13 +839,12 @@ private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.Button buttonLoadFile; - private System.Windows.Forms.Button buttonSave; + private System.Windows.Forms.Button button_selectFile; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.TabControl tabControl1; - private System.Windows.Forms.TextBox textBox_filePathLastTime; - private System.Windows.Forms.ContextMenuStrip contextMenuStrip_rowDel; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip_RowOps; private System.Windows.Forms.ToolStripMenuItem rowDelToolStripMenuItem; - private System.Windows.Forms.ContextMenuStrip contextMenuStrip_clmDel; + private System.Windows.Forms.ContextMenuStrip contextMenuStrip_ColumnOps; private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_delCurrentColumn; private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_delAllColumnsRightside; private System.Windows.Forms.TextBox textBox_regex_filter; @@ -374,6 +865,56 @@ private System.Windows.Forms.ToolStripMenuItem 关于ToolStripMenuItem; private System.Windows.Forms.ContextMenuStrip contextMenuStrip_tabcontrol; private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_tablcontrol_remove_page; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_SetAsHeader; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_deleteAllRowsBelow; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_displayRowColor; + private System.Windows.Forms.Button button_filter_preview_disable; + private System.Windows.Forms.Button button_filter_preview_enable; + private System.Windows.Forms.Button button_getContentAbove; + private System.Windows.Forms.Button button_applyColumnRuleToAllSheet; + private System.Windows.Forms.Button button_applyRowRuleToAllSheet; + private System.Windows.Forms.PageSetupDialog pageSetupDialog1; + public System.Windows.Forms.TextBox textBox_filePathLastTime; + private System.Windows.Forms.Button button_disselect_row_all; + private System.Windows.Forms.Button button_select_row_all; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_modify_column_name; + private System.Windows.Forms.Button button_selete_row_tag_as_deleted; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_OpenFile; + private System.Windows.Forms.ToolStripMenuItem 保存ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 另存为ToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_CloseMainForm; + private System.Windows.Forms.ToolStripComboBox toolStripComboBox1; + private System.Windows.Forms.ToolStripTextBox toolStripTextBox1; + private System.Windows.Forms.ToolStripMenuItem 开发中ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem opentestinteropexcelToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem formProgressToolStripMenuItem; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1; + private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1; + private System.Windows.Forms.ToolStripSplitButton toolStripSplitButton1; + private System.Windows.Forms.ToolStripMenuItem cToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem bToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem aToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem cToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem bToolStripMenuItem1; + private System.Windows.Forms.ToolStripMenuItem aToolStripMenuItem1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2; + private System.Windows.Forms.Button button_FormatFirstColumn; + private System.Windows.Forms.ToolStripMenuItem formDatePreviewToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem testPartialClassToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_setDateColumn; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_setNumberColumn; + private System.Windows.Forms.GroupBox groupBox5; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.ToolStripMenuItem testFormCombinedSheetToolStripMenuItem; } } diff --git a/ExcelToChart/Form1.cs b/ExcelToChart/Form1.cs index e5b09e8b0d92cfceba461279f5def68a2a3fd5f5..cf04126410ad4f2d90179d2d815544faf71309be 100644 --- a/ExcelToChart/Form1.cs +++ b/ExcelToChart/Form1.cs @@ -1,285 +1,346 @@ using System; using System.Windows.Forms; using System.Data; -using System.Data.OleDb; using System.IO; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Collections; +using System.Drawing; +using System.Threading; +using NPOI.SS.UserModel; +using NPOI.HSSF.UserModel; +using NPOI.XSSF.UserModel; namespace ExcelToChart { public partial class Form1 : Form { + FormProgressBar fpb; + Form_SheetSelect fss; + int rowIndex; - int columnIndex; - System.Drawing.Point mousePoint; - string pageName; - int clickedTabPageIndex; + int columnIndexAtMouse; + int selectedTabIndex; + int tabpageMouseHover = 0; + + public string filePath { set; get; } + FileStream stream; + public IWorkbook workbook; + public bool isCompatible; + public List activateSheetNames = new List(); + public List sheetInfo = new List(); + + DataSet dataOfAllSheets = new DataSet(); public Form1() { InitializeComponent(); + textBox_filePathLastTime.Text = Properties.Settings.Default.filePathLastTime; } - private DataTable CreateDataTableFromContent() + + public static void PrintTable(DataTable table) { - DataTable dt = new DataTable(); + // print head + PrintLine(12 * table.Columns.Count); + foreach (DataColumn col in table.Columns) + { + Console.Write(string.Format("{0,12}", col.Caption)); + } + Console.Write("\n"); + PrintLine(12 * table.Columns.Count); - foreach (DataGridViewColumn clm in dataGridView1.Columns) + // print rows + for (int i = 0; i < table.Rows.Count; i++) { - if (clm.Visible == true) + for (int j = 0; j < table.Columns.Count; j++) { - dt.Columns.Add(clm.HeaderText.Trim()); + Console.Write(string.Format("{0,12}", table.Rows[i][j].ToString())); } + Console.Write("\n"); + } + PrintLine(12 * table.Columns.Count, "-"); + } + /// + /// Print a line with specific char on to the console + /// + /// count of the char to be printed + /// the char to be printed, default is "=" + private static void PrintLine(int length, string lineChar = "=") + { + string line = string.Empty; + for (int i = 0; i < length; i++) + { + line += lineChar; } + Console.WriteLine(line); + } + + private DataTable CreateDataTableFromContent() + { + DataTable dts = dataGridView1.DataSource as DataTable; + DataTable dtd = new DataTable(); - // 循环行 - for (int count = 0; count < dataGridView1.Rows.Count; count++) + for (int i = dataGridView1.RowCount - 1; i >= 0; i--) { - DataRow dr = dt.NewRow(); - for (int countsub = 0; countsub < dataGridView1.Columns.Count; countsub++) + if (dataGridView1.Rows[i].DefaultCellStyle.ForeColor == Color.Red) { - if (dataGridView1.Columns[countsub].Visible == true) - { - dr[countsub] = Convert.ToString(dataGridView1.Rows[count].Cells[countsub].Value); - } + dts.Rows[i].Delete(); + } + } + dts.AcceptChanges(); + + for (int i = dataGridView1.ColumnCount - 1; i >= 0; i--) + { + if (dataGridView1.Columns[i].DefaultCellStyle.ForeColor == Color.Red) + { + dts.Columns.RemoveAt(i); } - dt.Rows.Add(dr); } - return dt; + PrintTable(dts); + return dts; } - private string getExcelOleDBConnectStr(string filePath) + + private string selectExcelFile() { - string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" - + "Data Source=" + @filePath + ";" + "Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'"; + OpenFileDialog file = new OpenFileDialog(); + file.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls"; + if (string.IsNullOrEmpty(Properties.Settings.Default.folderLastTime)) + { + file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + } + else + { + file.InitialDirectory = Properties.Settings.Default.folderLastTime; + } + + file.Multiselect = false; - return strConn; + if (file.ShowDialog() == DialogResult.Cancel) + return ""; + + return file.FileName; ; } - public ArrayList getExcelSheetNames(string filePath) + private void tabControl1_MouseClick(object sender, MouseEventArgs e) { - ArrayList arrayNames = new ArrayList(); - string strConn = getExcelOleDBConnectStr(filePath); - DataTable tb = null; - - try + if (e.Button == MouseButtons.Right) { - OleDbConnection conn = new OleDbConnection(strConn); - conn.Open(); - tb = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); - foreach (System.Data.DataRow drow in tb.Rows) - { - string sheetName = drow["TABLE_NAME"].ToString().Trim(); + contextMenuStrip_tabcontrol.Show(MousePosition); - int pos = sheetName.LastIndexOf('$'); - if ( (pos != -1) && (!sheetName.Contains("FilterDatabase") ) ) - { - arrayNames.Add(sheetName.Substring(0, pos)); - } + foreach (TabPage tp in tabControl1.TabPages) + { + if (tp.Bounds.Contains(e.X, e.Y)) + MessageBox.Show(tp.Text); } } - catch (System.Exception ex) + } + + private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + { + if (tabControl1.SelectedIndex != -1) { - MessageBox.Show(ex.Message); + selectedTabIndex = tabControl1.SelectedIndex; + Console.WriteLine(string.Format("selectpage {0} of {1}: ", selectedTabIndex, tabControl1.TabCount)); + dataGridView1.DataSource = null; + dataGridView1.DataSource = dataOfAllSheets.Tables[selectedTabIndex]; } + } - return arrayNames; + private void dataGridView1_DataSourceChanged(object sender, EventArgs e) + { } - public DataSet getData(string path) + private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { - ArrayList al = getExcelSheetNames(path); - - string fileSuffix = System.IO.Path.GetExtension(path); - if (string.IsNullOrEmpty(fileSuffix)) - return null; - - using (DataSet ds = new DataSet()) + Console.WriteLine(string.Format("dataGridView1_CellMouseUp at r:{0} c:{1}", e.RowIndex, e.ColumnIndex)); + if (e.Button == MouseButtons.Right) { - //判断Excel文件是2003版本还是2007版本 - string connString = ""; - - if (fileSuffix == ".xls") - connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\""; - else - connString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\""; - - //读取文件 - //string sql_select = " SELECT * FROM [Sheet1$]"; - string sql_select = " SELECT * FROM [" + al[0] + "$]"; - - using (OleDbConnection conn = new OleDbConnection(connString)) - - using (OleDbDataAdapter cmd = new OleDbDataAdapter(sql_select, conn)) + // click at column header(-1 row) + if (e.RowIndex == -1) { - conn.Open(); - - cmd.Fill(ds); + columnIndexAtMouse = e.ColumnIndex; + contextMenuStrip_ColumnOps.Show(Cursor.Position); + return; } - if (ds == null || ds.Tables.Count <= 0) return null; - - return ds; + // click at first column + if (e.ColumnIndex == -1) + { + contextMenuStrip_RowOps.Show(Cursor.Position); + return; + } + // normal cell clicked + return; } + } + private void dataGridView1_SortCompare(object sender, DataGridViewSortCompareEventArgs e) + { + dataGridView1.Sort(new NaturalSortComparer()); + MessageBox.Show("SortCompare " + e.ToString()); } + private void dataGridView1_Sorted(object sender, EventArgs e) + { + MessageBox.Show("TODO dataGridView1_Sorted"); + } - private String[] GetExcelSheetNames(string fileName) + private void buttonLoadFile_Click(object sender, EventArgs e) { - OleDbConnection objConn = null; - System.Data.DataTable dt = null; + string path = textBox_filePathLastTime.Text; + if (!File.Exists(path)) + { + MessageBox.Show("文件不存在,请重新选择 " + path); + return; + } + + string extension = Path.GetExtension(path); + if (!path.EndsWith(".xls", StringComparison.OrdinalIgnoreCase) && !path.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) + { + MessageBox.Show("文件扩展名错误, 请重新选择 " + extension); + return; + } + + // 记录本次选择的文件夹 + string folder = Path.GetDirectoryName(path); + Properties.Settings.Default.folderLastTime = folder; + Properties.Settings.Default.Save(); + + Properties.Settings.Default.ignoreEmptyRow = false; + Properties.Settings.Default.Save(); + + #region make workbook from file try { - string connString = string.Empty; - string FileType = fileName.Substring(fileName.LastIndexOf(".")); - if (FileType == ".xls") - connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + - "Data Source=" + fileName + ";Extended Properties=Excel 8.0;"; - else//.xlsx - connString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fileName + ";" + ";Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\""; - // 创建连接对象 - objConn = new OleDbConnection(connString); - // 打开数据库连接 - objConn.Open(); - // 得到包含数据架构的数据表 - dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); - if (dt == null) + stream = System.IO.File.OpenRead(filePath); + isCompatible = filePath.EndsWith(".xls", StringComparison.OrdinalIgnoreCase); + + if (isCompatible) { - return null; + workbook = new HSSFWorkbook(stream); } - String[] excelSheets = new String[dt.Rows.Count]; - int i = 0; - // 添加工作表名称到字符串数组 - foreach (DataRow row in dt.Rows) + else { - string strSheetTableName = row["TABLE_NAME"].ToString(); - //过滤无效SheetName - if (strSheetTableName.Contains("$") && strSheetTableName.Replace("'", "").EndsWith("$")) - { - excelSheets[i] = strSheetTableName.Substring(0, strSheetTableName.Length - 1); - } - i++; + workbook = new XSSFWorkbook(stream); } - return excelSheets; + + Console.WriteLine(workbook.NumberOfSheets); + + stream.Close(); } - catch (Exception ex) + catch { - MessageBox.Show(ex.ToString()); - return null; + MessageBox.Show("请关闭文件,再导入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; } finally { - // 清理 - if (objConn != null) + if (stream != null) { - objConn.Close(); - objConn.Dispose(); - } - if (dt != null) - { - dt.Dispose(); + stream.Close(); } + } - } + #endregion - private void buttonLoadFile_Click(object sender, EventArgs e) - { - dataGridView1.DataSource = null; //每次打开清空内容 - string path; - if (textBox_filePathLastTime.Text == "") + #region get all sheet names + activateSheetNames = ExcelHelper.GetSheetNames(workbook); + #endregion + + #region make dataset from activated sheet name + fss = new Form_SheetSelect(activateSheetNames); + fss.Owner = this; + + DialogResult dr = fss.ShowDialog(); + + if (dr == DialogResult.OK) { - //打开文件 - OpenFileDialog file = new OpenFileDialog(); - file.Filter = "Excel(*.xlsx)|*.xlsx|Excel(*.xls)|*.xls"; - file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); - file.Multiselect = false; + Console.WriteLine("sheet select ok"); - if (file.ShowDialog() == DialogResult.Cancel) + if (activateSheetNames.Count == 0) + { + Console.WriteLine("no sheet is selected"); return; + } - //判断文件后缀 - path = file.FileName; - } else + activateSheetNames = fss.selectedSheetNames; + + dataOfAllSheets = new DataSet(); + foreach (string sn in activateSheetNames) + { + //Console.WriteLine(sn); + ISheet sheet = workbook.GetSheet(sn); + DataTable dt = ExcelHelper.GetDataTableFromSheet(sheet, 2); + dataOfAllSheets.Tables.Add(dt); + } + } + else { - path = textBox_filePathLastTime.Text; + Console.WriteLine("sheet select cancel"); + return; } + - textBox_filePathLastTime.Text = path; - Properties.Settings.Default.filePathLastTime = path; - Properties.Settings.Default.Save(); - //string[] sheetNames = GetExcelSheetNames(path); - ArrayList sheetNames = getExcelSheetNames(path); - foreach (string sn in sheetNames) + Console.WriteLine("total datatable count:" + dataOfAllSheets.Tables.Count.ToString()); + + #endregion + + #region show tabcontrol, tabpages + + tabControl1.TabPages.Clear(); + + foreach (string sn in activateSheetNames) { - if(sn != "") + if (sn != "") { TabPage page = new TabPage(); page.Name = sn; page.Text = sn; tabControl1.TabPages.Add(page); } - } + selectedTabIndex = 0; - DataTable dt = getData(path).Tables[0]; + #endregion - dataGridView1.DataSource = dt; - } - - private void buttonSave_Click(object sender, EventArgs e) - { - - } + #region show default datagridview - private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) - { - if (e.Button == MouseButtons.Right) + dataGridView1.DataSource = null; //每次打开清空内容 + dataGridView1.Columns.Clear(); + dataGridView1.DataSource = dataOfAllSheets.Tables[selectedTabIndex]; + + foreach (DataGridViewColumn dgvc in dataGridView1.Columns) { - if(e.RowIndex == -1) - { - Console.WriteLine("click on header, column index="); - Console.WriteLine(e.ColumnIndex); - - dataGridView1.Columns[e.ColumnIndex].Selected = true; - this.columnIndex = e.ColumnIndex; - //this.dataGridView1.CurrentCell = this.dataGridView1.Columns[e.ColumnIndex]. - this.contextMenuStrip_clmDel.Show(this.dataGridView1, e.Location); - contextMenuStrip_clmDel.Show(Cursor.Position); - } else - { - this.dataGridView1.Rows[e.RowIndex].Selected = true; - this.rowIndex = e.RowIndex; - this.dataGridView1.CurrentCell = this.dataGridView1.Rows[e.RowIndex].Cells[1]; - this.contextMenuStrip_rowDel.Show(this.dataGridView1, e.Location); - contextMenuStrip_rowDel.Show(Cursor.Position); - } - + dgvc.SortMode = DataGridViewColumnSortMode.NotSortable; } + + #endregion + + textBox_filePathLastTime.Text = path; + Properties.Settings.Default.filePathLastTime = path; + Properties.Settings.Default.Save(); } - private void rowDelToolStripMenuItem_Click(object sender, EventArgs e) + private void buttonSelectFile_Click(object sender, EventArgs e) { - if(!this.dataGridView1.Rows[this.rowIndex].IsNewRow) - { - this.dataGridView1.Rows.RemoveAt(this.rowIndex); - } + string path = selectExcelFile(); + textBox_filePathLastTime.Text = path; } - + private void button_keep_rows_by_regex_Click(object sender, EventArgs e) { string pattern = textBox_regex_filter.Text; List strs = new List(); - for (int row = 1; row < dataGridView1.RowCount-1; row++) + for (int row = 1; row < dataGridView1.RowCount - 1; row++) { string v = dataGridView1[0, row].Value.ToString(); strs.Add(v); @@ -294,34 +355,66 @@ namespace ExcelToChart private void button_remove_rows_by_regex_Click(object sender, EventArgs e) { - foreach(DataGridViewRow row in dataGridView1.Rows) + if (dataGridView1.Rows.Count > 0) { - if(row.Selected == true) + foreach (DataGridViewRow row in dataGridView1.Rows) { - row.Selected = false; - } else - { - row.Selected = true; + if (row.Selected == true) + { + row.Selected = false; + } + else + { + row.Selected = true; + } } + + dataGridView1.Rows[dataGridView1.NewRowIndex].Selected = false; + } + } - dataGridView1.Rows[dataGridView1.NewRowIndex].Selected = false; + private void button_select_row_all_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow row in dataGridView1.Rows) + { + row.Selected = true; + } } - private void button_delete_selected_rows_Click(object sender, EventArgs e) + private void button_selete_row_tag_as_deleted_Click(object sender, EventArgs e) { - /*foreach (DataGridViewRow row in dataGridView1.Rows) + if (dataGridView1.Rows.Count > 0) { - if (row.Selected == true) + foreach (DataGridViewRow row in dataGridView1.Rows) { - dataGridView1.Rows.RemoveAt(row.Index); + if (row.DefaultCellStyle.ForeColor == Color.Red) + { + row.Selected = true; + } + else + { + row.Selected = false; + } } - - }*/ - //dataGridView1.SelectedRows.remo + } + } + + private void button_disselect_row_all_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow row in dataGridView1.Rows) + { + row.Selected = false; + } + } + + private void button_delete_selected_rows_Click(object sender, EventArgs e) + { foreach (DataGridViewRow row in dataGridView1.SelectedRows) { - dataGridView1.Rows.Remove(row); + //dataGridView1.Rows.Remove(row); + row.DefaultCellStyle.ForeColor = Color.Red; + row.Selected = false; } } @@ -329,8 +422,6 @@ namespace ExcelToChart { Form_Chart fc = new Form_Chart(CreateDataTableFromContent()); fc.Show(); - - } private void button_show_Histogram_Click(object sender, EventArgs e) @@ -339,45 +430,281 @@ namespace ExcelToChart fc.Show(); } - private void tabControl1_MouseClick(object sender, MouseEventArgs e) + private void ToolStripMenuItem_tablcontrol_remove_page_Click(object sender, EventArgs e) + { + tabControl1.TabPages.RemoveAt(tabpageMouseHover); + } + + private void ToolStripMenuItem_delCurrentColumn_Click(object sender, EventArgs e) { - if(e.Button == MouseButtons.Right) + //if(!this.dataGridView1.Columns[this.columnIndex].is) + //this.dataGridView1.Columns.RemoveAt(this.columnIndex); + //dataGridView1.Columns[columnIndex].DefaultCellStyle.ForeColor = Color.Red; + if (dataGridView1.Columns[columnIndexAtMouse].DefaultCellStyle.ForeColor == Color.Red) { - contextMenuStrip_tabcontrol.Show(MousePosition); - mousePoint = MousePosition; + dataGridView1.Columns[columnIndexAtMouse].DefaultCellStyle.ForeColor = Color.Empty; + } + else + { + dataGridView1.Columns[columnIndexAtMouse].DefaultCellStyle.ForeColor = Color.Red; + } + } - foreach (TabPage tp in tabControl1.TabPages) + private void ToolStripMenuItem_delAllColumnsRightside_Click(object sender, EventArgs e) + { + for (int clm = this.columnIndexAtMouse + 1; clm < dataGridView1.Columns.Count; clm++) + { + //this.dataGridView1.Columns.RemoveAt(this.columnIndex); + //dataGridView1.Columns[clm].Visible = false; + //dataGridView1.Columns[clm].DefaultCellStyle.ForeColor = Color.Red; + if (dataGridView1.Columns[clm].DefaultCellStyle.ForeColor == Color.Red) { - if (tp.Bounds.Contains(e.X, e.Y)) - MessageBox.Show(tp.Text); - + dataGridView1.Columns[clm].DefaultCellStyle.ForeColor = Color.Empty; } + else + { + dataGridView1.Columns[clm].DefaultCellStyle.ForeColor = Color.Red; + } + } } - private void ToolStripMenuItem_tablcontrol_remove_page_Click(object sender, EventArgs e) + private void ToolStripMenuItem_modify_column_name_Click(object sender, EventArgs e) { - if (tabControl1.SelectedTab != null) tabControl1.TabPages.Remove(tabControl1.SelectedTab); + // TODO + dataGridView1.Columns[columnIndexAtMouse].HeaderText = "new name"; } - private void ToolStripMenuItem_delCurrentColumn_Click(object sender, EventArgs e) + private void ToolStripMenuItem_opentestinteropexcel_Click(object sender, EventArgs e) { - //if(!this.dataGridView1.Columns[this.columnIndex].is) - this.dataGridView1.Columns.RemoveAt(this.columnIndex); + } - private void ToolStripMenuItem_delAllColumnsRightside_Click(object sender, EventArgs e) + private void ToolStripMenuItem_SetAsHeader_Click(object sender, EventArgs e) { - for (int clm = this.columnIndex + 1; clm < dataGridView1.Columns.Count; clm++) + DataGridViewRow rowSelected = dataGridView1.SelectedRows[0]; + int selectedRowIndex = rowSelected.Index; + + for (int i = 0; i < dataGridView1.Columns.Count; i++) { - //this.dataGridView1.Columns.RemoveAt(this.columnIndex); - dataGridView1.Columns[clm].Visible = false; + dataGridView1.Columns[i].HeaderCell.Value = rowSelected.Cells[i].Value; + } + + for (int i = 0; i <= selectedRowIndex; i++) + { + (dataGridView1.DataSource as DataTable).Rows.RemoveAt(0); } } - private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) + private void ToolStripMenuItem_deleteCurrentRow_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow dgvr in dataGridView1.SelectedRows) + { + if (!dgvr.IsNewRow) + { + if (dgvr.DefaultCellStyle.ForeColor == Color.Empty) + { + dgvr.DefaultCellStyle.ForeColor = Color.Red; + } + else + { + dgvr.DefaultCellStyle.ForeColor = Color.Empty; + } + } + } + } + + private void ToolStripMenuItem_deleteAllRowsBelow_Click(object sender, EventArgs e) + { + for (int rowId = rowIndex + 1; rowId < dataGridView1.Rows.Count - 1; rowId++) + { + dataGridView1.Rows[rowId].DefaultCellStyle.ForeColor = Color.Red; + } + } + + private void ToolStripMenuItem_displayRowColor_Click(object sender, EventArgs e) + { + Color c = dataGridView1.Rows[rowIndex].DefaultCellStyle.ForeColor; + MessageBox.Show("color: " + c.ToString()); + } + + private void tabControl1_MouseMove(object sender, MouseEventArgs e) { - MessageBox.Show(tabControl1.SelectedIndex.ToString() + " " + tabControl1.SelectedTab.Text); + for (var i = 0; i < this.tabControl1.TabPages.Count; i++) + { + var tabRect = this.tabControl1.GetTabRect(i); + if (tabRect.Contains(e.Location)) + { + //Console.WriteLine(tabControl1.TabPages[i].Text); + tabpageMouseHover = i; + } + } + } + + private void button_filter_preview_enable_Click(object sender, EventArgs e) + { + CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource]; + currencyManager1.SuspendBinding(); + + foreach (DataGridViewColumn dgvc in dataGridView1.Columns) + { + if (dgvc.DefaultCellStyle.ForeColor == Color.Red) + { + dgvc.Visible = false; + } + } + + for (int rn = dataGridView1.Rows.Count - 1; rn >= 0; rn--) + { + if (dataGridView1.Rows[rn].DefaultCellStyle.ForeColor == Color.Red) + { + dataGridView1.Rows[rn].Visible = false; + } + } + + currencyManager1.ResumeBinding(); + } + + private void button_filter_preview_disable_Click(object sender, EventArgs e) + { + CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource]; + currencyManager1.SuspendBinding(); + + foreach (DataGridViewColumn dgvc in dataGridView1.Columns) + { + dgvc.Visible = true; + } + + for (int rn = dataGridView1.Rows.Count - 1; rn >= 0; rn--) + { + dataGridView1.Rows[rn].Visible = true; + } + + currencyManager1.ResumeBinding(); + } + + private void button_getContentAbove_Click(object sender, EventArgs e) + { + int cellsInColumn = dataGridView1.Rows.Count; + + for (int i = 0; i < cellsInColumn - 1; i++) + { + DataGridViewRow dgvr = dataGridView1.Rows[i]; + if (dgvr.DefaultCellStyle.ForeColor != Color.Red) + { + if (i - 1 < 0) + { + continue; + } + string s1 = dgvr.Cells[0].Value.ToString(); + string s2 = dataGridView1.Rows[i - 1].Cells[0].Value.ToString(); + string s = string.Format("{0}-{1}", s1, s2); + + + //dgvr.Cells[0].Value = dgvr.Cells[0].Value.ToString() + dataGridView1.Rows[i].Cells[0].Value.ToString(); + dgvr.Cells[0].Value = s; + } + } + } + + private void button_applyRowRuleToAllSheet_Click(object sender, EventArgs e) + { + + } + + private void button_applyColumnRuleToAllSheet_Click(object sender, EventArgs e) + { + + } + + private void formProgressToolStripMenuItem_Click(object sender, EventArgs e) + { + FormProgressBar fpb = new FormProgressBar(); + fpb.Show(); + } + + private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) + { + + } + + private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) + { + + } + + private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) + { + + } + + private void textBox_filePathLastTime_TextChanged(object sender, EventArgs e) + { + filePath = textBox_filePathLastTime.Text; + } + + private void ToolStripMenuItem_CloseMainForm_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void ToolStripMenuItem_OpenFile_Click(object sender, EventArgs e) + { + filePath = selectExcelFile(); + toolStripStatusLabel2.Text = filePath; + } + + private void button_FormatFirstColumn_Click(object sender, EventArgs e) + { + List originTextList = new List(); + List formatTextList = new List(); + + for (int rn = 0; rn < dataGridView1.Rows.Count - 1; rn++) + { + DataGridViewCell dgvc = dataGridView1.Rows[rn].Cells[0]; + + if (dgvc.Visible == false || dataGridView1.Rows[rn].DefaultCellStyle.ForeColor == Color.Red) + { + continue; + } + + originTextList.Add(dgvc.Value.ToString()); + formatTextList.Add(dgvc.Value.ToString()); + } + + Form_DateFormat fdp = new Form_DateFormat(originTextList, formatTextList); + fdp.ShowDialog(); + } + + private void formDatePreviewToolStripMenuItem_Click(object sender, EventArgs e) + { + Form_DateFormat fdp = new Form_DateFormat(); + fdp.ShowDialog(); + } + + private void testPartialClassToolStripMenuItem_Click(object sender, EventArgs e) + { + myPartialFunction(); + } + + private void ToolStripMenuItem_setDateColumn_Click(object sender, EventArgs e) + { + Console.WriteLine("ToolStripMenuItem_setDateColumn_Click"); + dataGridView1.Columns[columnIndexAtMouse].DefaultCellStyle.BackColor = Color.FromArgb(200, 255, 255); + } + + private void ToolStripMenuItem_setNumberColumn_Click(object sender, EventArgs e) + { + Console.WriteLine("ToolStripMenuItem_setNumberColumn_Click"); + dataGridView1.Columns[columnIndexAtMouse].DefaultCellStyle.BackColor = Color.FromArgb(255, 200, 255); + } + + private void testFormCombinedSheetToolStripMenuItem_Click(object sender, EventArgs e) + { + Form_CombinedSheet fcs = new Form_CombinedSheet(); + + + fcs.ShowDialog(); } } } diff --git a/ExcelToChart/Form1.resx b/ExcelToChart/Form1.resx index c105251d9a2c695e8e3b3096abc392f5944d3bdd..8771cf0ba04bc87f3d4214db7d8a88b02044ba9b 100644 --- a/ExcelToChart/Form1.resx +++ b/ExcelToChart/Form1.resx @@ -118,21 +118,58 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 17, 17 + 174, 43 - - 157, 17 + + 148, 11 - - 350, 17 + + 345, 12 - 541, 17 + 24, 9 - 656, 17 + 569, 11 - - 92 + + 17, 43 + + 347, 44 + + + 541, 42 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + \ No newline at end of file diff --git a/ExcelToChart/FormProgressBar.Designer.cs b/ExcelToChart/FormProgressBar.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..156c56c8beacf97120a424f2aac8f30f9bdc96dd --- /dev/null +++ b/ExcelToChart/FormProgressBar.Designer.cs @@ -0,0 +1,93 @@ +namespace ExcelToChart +{ + partial class FormProgressBar + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.progressBar1 = new System.Windows.Forms.ProgressBar(); + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // progressBar1 + // + this.progressBar1.Location = new System.Drawing.Point(82, 95); + this.progressBar1.Name = "progressBar1"; + this.progressBar1.Size = new System.Drawing.Size(407, 35); + this.progressBar1.TabIndex = 0; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(254, 185); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 1; + this.button1.Text = "中止"; + this.button1.UseVisualStyleBackColor = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(252, 21); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(29, 12); + this.label1.TabIndex = 2; + this.label1.Text = "任务"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(254, 51); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(29, 12); + this.label2.TabIndex = 3; + this.label2.Text = "步骤"; + // + // FormProgressBar + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(580, 273); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Controls.Add(this.progressBar1); + this.Name = "FormProgressBar"; + this.Text = "FormProgressBar"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + public System.Windows.Forms.ProgressBar progressBar1; + } +} \ No newline at end of file diff --git a/ExcelToChart/FormProgressBar.cs b/ExcelToChart/FormProgressBar.cs new file mode 100644 index 0000000000000000000000000000000000000000..52939fa2baafe83c530d49f17ce68d06a0dae973 --- /dev/null +++ b/ExcelToChart/FormProgressBar.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class FormProgressBar : Form + { + public int value; + public int max; + public FormProgressBar() + { + InitializeComponent(); + } + + public FormProgressBar(string title) + { + InitializeComponent(); + this.Text = title; + } + } +} diff --git a/ExcelToChart/FormProgressBar.resx b/ExcelToChart/FormProgressBar.resx new file mode 100644 index 0000000000000000000000000000000000000000..1af7de150c99c12dd67a509fe57c10d63e4eeb04 --- /dev/null +++ b/ExcelToChart/FormProgressBar.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ExcelToChart/Form_Chart.Designer.cs b/ExcelToChart/Form_Chart.Designer.cs index 49e912beccd9254ac4e966eb30a754e063235a9c..4f35bbf458ee37f9136a6abe30901f7ffc5f6551 100644 --- a/ExcelToChart/Form_Chart.Designer.cs +++ b/ExcelToChart/Form_Chart.Designer.cs @@ -34,10 +34,10 @@ System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.comboBox_chart_selections = new System.Windows.Forms.ComboBox(); + this.button_save_chart = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); + this.comboBox_chart_selections = new System.Windows.Forms.ComboBox(); this.contextMenuStrip_save_chart = new System.Windows.Forms.ContextMenuStrip(this.components); - this.button_save_chart = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); @@ -75,12 +75,31 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "groupBox1"; // + // button_save_chart + // + this.button_save_chart.Location = new System.Drawing.Point(66, 382); + this.button_save_chart.Name = "button_save_chart"; + this.button_save_chart.Size = new System.Drawing.Size(75, 23); + this.button_save_chart.TabIndex = 5; + this.button_save_chart.Text = "保存为图片"; + this.button_save_chart.UseVisualStyleBackColor = true; + this.button_save_chart.Click += new System.EventHandler(this.button_save_chart_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(79, 284); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 4; + this.label1.Text = "label1"; + // // comboBox_chart_selections // this.comboBox_chart_selections.FormattingEnabled = true; this.comboBox_chart_selections.Items.AddRange(new object[] { - "折线图", "柱状图", + "折线图", "饼状图", "雷达图", "曲线图", @@ -90,31 +109,13 @@ this.comboBox_chart_selections.Name = "comboBox_chart_selections"; this.comboBox_chart_selections.Size = new System.Drawing.Size(121, 20); this.comboBox_chart_selections.TabIndex = 3; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(79, 284); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(41, 12); - this.label1.TabIndex = 4; - this.label1.Text = "label1"; + this.comboBox_chart_selections.Text = "柱状图"; // // contextMenuStrip_save_chart // this.contextMenuStrip_save_chart.Name = "contextMenuStrip_save_chart"; this.contextMenuStrip_save_chart.Size = new System.Drawing.Size(61, 4); // - // button_save_chart - // - this.button_save_chart.Location = new System.Drawing.Point(66, 382); - this.button_save_chart.Name = "button_save_chart"; - this.button_save_chart.Size = new System.Drawing.Size(75, 23); - this.button_save_chart.TabIndex = 5; - this.button_save_chart.Text = "保存为图片"; - this.button_save_chart.UseVisualStyleBackColor = true; - this.button_save_chart.Click += new System.EventHandler(this.button_save_chart_Click); - // // Form_Chart // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); diff --git a/ExcelToChart/Form_Chart.cs b/ExcelToChart/Form_Chart.cs index 3b53aeacfa552093f4b7756b91ee4d13d94d68af..98fd59053850788b34b8720c7125b0bdd51ed08a 100644 --- a/ExcelToChart/Form_Chart.cs +++ b/ExcelToChart/Form_Chart.cs @@ -16,11 +16,6 @@ namespace ExcelToChart public Form_Chart() { InitializeComponent(); - /*List xData = new List() { "A", "B", "C", "D" }; - List yData = new List() { 10, 20, 30, 40 }; - chart1.Series[0]["PieLabelStyle"] = "Outside";//将文字移到外侧 - chart1.Series[0]["PieLineColor"] = "Black";//绘制黑色的连线。 - chart1.Series[0].Points.DataBindXY(xData, yData);*/ } public Form_Chart(DataTable dt) @@ -32,7 +27,18 @@ namespace ExcelToChart private void Form_Chart_Load(object sender, EventArgs e) { DataTable dt = chartDataSource; + int sc = chart1.Series.Count; + + if (dt.Columns.Count <= 1) + { + MessageBox.Show("源数据只有小于等于1列,无法生成图表"); + return; + } + + chart1.Series[0].Name = dt.Columns[0].ColumnName; + + for (int i = sc; i < dt.Columns.Count; i++) { Console.WriteLine(dt.Columns[i].ColumnName); diff --git a/ExcelToChart/Form_CombinedSheet.Designer.cs b/ExcelToChart/Form_CombinedSheet.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..22fbf57dfb49902c9862146b217062132698c16f --- /dev/null +++ b/ExcelToChart/Form_CombinedSheet.Designer.cs @@ -0,0 +1,259 @@ +namespace ExcelToChart +{ + partial class Form_CombinedSheet + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.Column_Date = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column_Count_DGV1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.dataGridView2 = new System.Windows.Forms.DataGridView(); + this.Column_Week = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column_Count_DGV2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.button_week_report = new System.Windows.Forms.Button(); + this.button_month_report = new System.Windows.Forms.Button(); + this.dataGridView3 = new System.Windows.Forms.DataGridView(); + this.Column_Mont = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column_Count_DGV3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.选项ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ToolStripMenuItem_load_test_data = new System.Windows.Forms.ToolStripMenuItem(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).BeginInit(); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Date, + this.Column_Count_DGV1}); + this.dataGridView1.Location = new System.Drawing.Point(22, 70); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 23; + this.dataGridView1.Size = new System.Drawing.Size(253, 365); + this.dataGridView1.TabIndex = 0; + // + // Column_Date + // + this.Column_Date.HeaderText = "日期"; + this.Column_Date.Name = "Column_Date"; + // + // Column_Count_DGV1 + // + this.Column_Count_DGV1.HeaderText = "数量"; + this.Column_Count_DGV1.Name = "Column_Count_DGV1"; + // + // dataGridView2 + // + this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView2.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Week, + this.Column_Count_DGV2}); + this.dataGridView2.Location = new System.Drawing.Point(281, 70); + this.dataGridView2.Name = "dataGridView2"; + this.dataGridView2.RowTemplate.Height = 23; + this.dataGridView2.Size = new System.Drawing.Size(253, 365); + this.dataGridView2.TabIndex = 1; + // + // Column_Week + // + this.Column_Week.HeaderText = "年周"; + this.Column_Week.Name = "Column_Week"; + // + // Column_Count_DGV2 + // + this.Column_Count_DGV2.HeaderText = "数量"; + this.Column_Count_DGV2.Name = "Column_Count_DGV2"; + // + // button_week_report + // + this.button_week_report.Location = new System.Drawing.Point(281, 455); + this.button_week_report.Name = "button_week_report"; + this.button_week_report.Size = new System.Drawing.Size(75, 23); + this.button_week_report.TabIndex = 2; + this.button_week_report.Text = "生成年周报告"; + this.button_week_report.UseVisualStyleBackColor = true; + this.button_week_report.Click += new System.EventHandler(this.button_week_report_Click); + // + // button_month_report + // + this.button_month_report.Location = new System.Drawing.Point(540, 455); + this.button_month_report.Name = "button_month_report"; + this.button_month_report.Size = new System.Drawing.Size(75, 23); + this.button_month_report.TabIndex = 3; + this.button_month_report.Text = "生成年月报告"; + this.button_month_report.UseVisualStyleBackColor = true; + this.button_month_report.Click += new System.EventHandler(this.button_month_report_Click); + // + // dataGridView3 + // + this.dataGridView3.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView3.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column_Mont, + this.Column_Count_DGV3}); + this.dataGridView3.Location = new System.Drawing.Point(540, 70); + this.dataGridView3.Name = "dataGridView3"; + this.dataGridView3.RowTemplate.Height = 23; + this.dataGridView3.Size = new System.Drawing.Size(253, 365); + this.dataGridView3.TabIndex = 4; + // + // Column_Mont + // + this.Column_Mont.HeaderText = "月份"; + this.Column_Mont.Name = "Column_Mont"; + // + // Column_Count_DGV3 + // + this.Column_Count_DGV3.HeaderText = "数量"; + this.Column_Count_DGV3.Name = "Column_Count_DGV3"; + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.文件ToolStripMenuItem, + this.选项ToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(826, 24); + this.menuStrip1.TabIndex = 5; + this.menuStrip1.Text = "menuStrip1"; + // + // 文件ToolStripMenuItem + // + this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem"; + this.文件ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.文件ToolStripMenuItem.Text = "文件"; + // + // 选项ToolStripMenuItem + // + this.选项ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.ToolStripMenuItem_load_test_data}); + this.选项ToolStripMenuItem.Name = "选项ToolStripMenuItem"; + this.选项ToolStripMenuItem.Size = new System.Drawing.Size(45, 20); + this.选项ToolStripMenuItem.Text = "选项"; + // + // ToolStripMenuItem_load_test_data + // + this.ToolStripMenuItem_load_test_data.Name = "ToolStripMenuItem_load_test_data"; + this.ToolStripMenuItem_load_test_data.Size = new System.Drawing.Size(180, 22); + this.ToolStripMenuItem_load_test_data.Text = "载入测试数据"; + this.ToolStripMenuItem_load_test_data.Click += new System.EventHandler(this.ToolStripMenuItem_load_test_data_Click); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(362, 455); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 6; + this.button1.Text = "导出报表"; + this.button1.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(443, 455); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 7; + this.button2.Text = "生成图表"; + this.button2.UseVisualStyleBackColor = true; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(621, 455); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 8; + this.button3.Text = "导出报表"; + this.button3.UseVisualStyleBackColor = true; + // + // button4 + // + this.button4.Location = new System.Drawing.Point(702, 455); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 9; + this.button4.Text = "生成图表"; + this.button4.UseVisualStyleBackColor = true; + // + // Form_CombinedSheet + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(826, 518); + this.Controls.Add(this.button4); + this.Controls.Add(this.button3); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.dataGridView3); + this.Controls.Add(this.button_month_report); + this.Controls.Add(this.button_week_report); + this.Controls.Add(this.dataGridView2); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "Form_CombinedSheet"; + this.Text = "Form_CombinedSheet"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView3)).EndInit(); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private System.Windows.Forms.DataGridView dataGridView2; + private System.Windows.Forms.Button button_week_report; + private System.Windows.Forms.Button button_month_report; + private System.Windows.Forms.DataGridView dataGridView3; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Date; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV1; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Week; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV2; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Mont; + private System.Windows.Forms.DataGridViewTextBoxColumn Column_Count_DGV3; + public System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.MenuStrip menuStrip1; + private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem 选项ToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_load_test_data; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; + } +} \ No newline at end of file diff --git a/ExcelToChart/Form_CombinedSheet.cs b/ExcelToChart/Form_CombinedSheet.cs new file mode 100644 index 0000000000000000000000000000000000000000..5a3bb6bf829de0e32760c60947adfd8944b24249 --- /dev/null +++ b/ExcelToChart/Form_CombinedSheet.cs @@ -0,0 +1,202 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class Form_CombinedSheet : Form + { + DataTable date_number_datatable; + public Form_CombinedSheet() + { + InitializeComponent(); + } + + public Form_CombinedSheet(DataTable dt) + { + date_number_datatable = dt; + InitializeComponent(); + } + + public static DataTable getTestDataTable() + { + DataTable tdt = new DataTable(); + + DataColumn dateDataColumn = tdt.Columns.Add("Date"); + DataColumn countDataColumn = tdt.Columns.Add("Count"); + Random rd = new Random(); + + for (int i = 1; i <= 31; i++) + { + DataRow dr = tdt.NewRow(); + dr[0] = string.Format("2021-05-{0:D2}", i); + dr[1] = rd.Next(1000, 3000); + tdt.Rows.Add(dr); + } + + for (int i = 1; i <= 30; i++) + { + DataRow dr = tdt.NewRow(); + dr[0] = string.Format("2021-06-{0:D2}", i); + dr[1] = rd.Next(1000, 3000); + tdt.Rows.Add(dr); + } + + return tdt; + } + + public static DataTable datatableDateFormat(DataTable dt) + { + DataTable dtf = dt.Copy(); + + for (int i = 0; i < dt.Rows.Count; i++) + { + DateTime date; + try + { + date = DateTime.ParseExact(dt.Rows[i][0].ToString(), "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); + } + catch(Exception e) + { + MessageBox.Show(e.ToString() + "TODO: 需要手动修正错误"); + continue; + } + + dtf.Rows[i][0] = date; + } + + return dtf; + } + + private void button_week_report_Click(object sender, EventArgs e) + { + DataTable dtf = datatableDateFormat(date_number_datatable); + + var keys = new DataColumn[1]; + DataTable dtWeekCombine = new DataTable(); + DataColumn column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.String"); + column.ColumnName = "年-周"; + dtWeekCombine.Columns.Add(column); + keys[0] = column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.Int32"); + column.ColumnName = "数量"; + dtWeekCombine.Columns.Add(column); + //keys[1] = column; + + dtWeekCombine.PrimaryKey = keys; + + for (int i =0; i< dtf.Rows.Count; i++) + { + int value = int.Parse(dtf.Rows[i][1].ToString()); + DateTime dateOfRow = DateTime.Parse(dtf.Rows[i][0].ToString()); + + int year = dateOfRow.Year; + GregorianCalendar gc = new GregorianCalendar(); + int weekOfYear = gc.GetWeekOfYear(dateOfRow, CalendarWeekRule.FirstDay, DayOfWeek.Monday); + //Console.WriteLine(weekOfYear); + //Console.ReadLine(); + + //string key = year.ToString() + "-" + weekOfYear.ToString(); + string key = string.Format("{0}-{1}", year, weekOfYear); + DataRow dr = dtWeekCombine.Rows.Find(key); + if(dr != null) + { + //已经有这个年-周的key了. 插入 + dr[1] = (int)dr[1] + value; + } + else + { + //新的一周, 新建一个row + DataRow newRow = dtWeekCombine.NewRow(); + newRow[0] = key; + newRow[1] = value; + dtWeekCombine.Rows.Add(newRow); + } + } + + dataGridView2.Columns.Clear(); + dataGridView2.DataSource = dtWeekCombine; + } + + private void button_month_report_Click(object sender, EventArgs e) + { + DataTable dtf = datatableDateFormat(date_number_datatable); + + var keys = new DataColumn[1]; + DataTable dtMonthCombine = new DataTable(); + DataColumn column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.String"); + column.ColumnName = "年-月"; + dtMonthCombine.Columns.Add(column); + keys[0] = column; + + column = new DataColumn(); + column.DataType = Type.GetType("System.Int32"); + column.ColumnName = "数量"; + dtMonthCombine.Columns.Add(column); + //keys[1] = column; + + dtMonthCombine.PrimaryKey = keys; + + for (int i = 0; i < dtf.Rows.Count; i++) + { + int value = int.Parse(dtf.Rows[i][1].ToString()); + DateTime dateOfRow = DateTime.Parse(dtf.Rows[i][0].ToString()); + + int year = dateOfRow.Year; + int month = dateOfRow.Month; + //GregorianCalendar gc = new GregorianCalendar(); + //int weekOfYear = gc.GetWeekOfYear(dateOfRow, CalendarWeekRule.FirstDay, DayOfWeek.Monday); + //Console.WriteLine(weekOfYear); + //Console.ReadLine(); + + string key = string.Format("{0}-{1}", year, month); + DataRow dr = dtMonthCombine.Rows.Find(key); + if (dr != null) + { + //已经有这个年-周的key了. 插入 + dr[1] = (int)dr[1] + value; + } + else + { + //新的一周, 新建一个row + DataRow newRow = dtMonthCombine.NewRow(); + newRow[0] = key; + newRow[1] = value; + dtMonthCombine.Rows.Add(newRow); + } + } + + dataGridView3.Columns.Clear(); + dataGridView3.DataSource = dtMonthCombine; + } + + private void ToolStripMenuItem_load_test_data_Click(object sender, EventArgs e) + { + // 拿到原始数据, 日期为字符串 + date_number_datatable = getTestDataTable(); + + foreach (DataRow dr in date_number_datatable.Rows) + { + Console.WriteLine(dr.ToString()); + } + + dataGridView1.Columns.Clear(); + dataGridView1.DataSource = date_number_datatable; + } + } +} diff --git a/ExcelToChart/Form_CombinedSheet.resx b/ExcelToChart/Form_CombinedSheet.resx new file mode 100644 index 0000000000000000000000000000000000000000..4629e871d062a119dd8e371ab1d0be53f3597862 --- /dev/null +++ b/ExcelToChart/Form_CombinedSheet.resx @@ -0,0 +1,159 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/ExcelToChart/Form_DateFormat.Designer.cs b/ExcelToChart/Form_DateFormat.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..f6bc83525a7fe6a288340dd44f028b089fd228a0 --- /dev/null +++ b/ExcelToChart/Form_DateFormat.Designer.cs @@ -0,0 +1,118 @@ +namespace ExcelToChart +{ + partial class Form_DateFormat + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.button_end_cancel = new System.Windows.Forms.Button(); + this.button_end_ok = new System.Windows.Forms.Button(); + this.OriginText = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.FormatAsDatetime = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.button_Format = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.OriginText, + this.FormatAsDatetime}); + this.dataGridView1.Location = new System.Drawing.Point(12, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 23; + this.dataGridView1.Size = new System.Drawing.Size(540, 426); + this.dataGridView1.TabIndex = 12; + // + // button_end_cancel + // + this.button_end_cancel.Location = new System.Drawing.Point(619, 380); + this.button_end_cancel.Name = "button_end_cancel"; + this.button_end_cancel.Size = new System.Drawing.Size(119, 33); + this.button_end_cancel.TabIndex = 14; + this.button_end_cancel.Text = "取消"; + this.button_end_cancel.UseVisualStyleBackColor = true; + this.button_end_cancel.Click += new System.EventHandler(this.button_end_cancel_Click); + // + // button_end_ok + // + this.button_end_ok.Location = new System.Drawing.Point(619, 322); + this.button_end_ok.Name = "button_end_ok"; + this.button_end_ok.Size = new System.Drawing.Size(119, 33); + this.button_end_ok.TabIndex = 13; + this.button_end_ok.Text = "确定"; + this.button_end_ok.UseVisualStyleBackColor = true; + this.button_end_ok.Click += new System.EventHandler(this.button_end_ok_Click); + // + // OriginText + // + this.OriginText.HeaderText = "列原始内容"; + this.OriginText.Name = "OriginText"; + this.OriginText.ReadOnly = true; + // + // FormatAsDatetime + // + this.FormatAsDatetime.HeaderText = "格式化后日期"; + this.FormatAsDatetime.Name = "FormatAsDatetime"; + // + // button_Format + // + this.button_Format.Location = new System.Drawing.Point(619, 59); + this.button_Format.Name = "button_Format"; + this.button_Format.Size = new System.Drawing.Size(131, 72); + this.button_Format.TabIndex = 15; + this.button_Format.Text = "格式化"; + this.button_Format.UseVisualStyleBackColor = true; + this.button_Format.Click += new System.EventHandler(this.button_Format_Click); + // + // Form_DatePreview + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.button_Format); + this.Controls.Add(this.dataGridView1); + this.Controls.Add(this.button_end_cancel); + this.Controls.Add(this.button_end_ok); + this.Name = "Form_DatePreview"; + this.Text = "Form_DatePreview"; + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.Button button_end_cancel; + private System.Windows.Forms.Button button_end_ok; + private System.Windows.Forms.DataGridViewTextBoxColumn OriginText; + private System.Windows.Forms.DataGridViewTextBoxColumn FormatAsDatetime; + private System.Windows.Forms.Button button_Format; + } +} \ No newline at end of file diff --git a/ExcelToChart/Form_DateFormat.cs b/ExcelToChart/Form_DateFormat.cs new file mode 100644 index 0000000000000000000000000000000000000000..a3e73247b8741b932fe73b62bc72bffed6c9cc58 --- /dev/null +++ b/ExcelToChart/Form_DateFormat.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class Form_DateFormat : Form + { + public List originTextList { set; get; } + public List formatTextList { set; get; } + + public Form_DateFormat() + { + InitializeComponent(); + } + + public void datagridFillOriginData() + { + for(int i = 0; i < originTextList.Count; i++) + { + int index = this.dataGridView1.Rows.Add(); + dataGridView1.Rows[index].Cells[0].Value = originTextList[i]; + dataGridView1.Rows[index].Cells[1].Value = formatTextList[i]; + } + } + + public Form_DateFormat(List origin, List format) + { + originTextList = origin; + formatTextList = format; + + InitializeComponent(); + + datagridFillOriginData(); + } + + private void button_end_ok_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void button_end_cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void button_Format_Click(object sender, EventArgs e) + { + for (int i = 0; i < originTextList.Count; i++) + { + + string result = System.Text.RegularExpressions.Regex.Replace(dataGridView1.Rows[i].Cells[0].Value.ToString(), @"[^0-9]+", ""); + int num = int.Parse(result); + Console.WriteLine("get num " + num.ToString()); + + + // TODO + //dataGridView1.Rows[i].Cells[0].Value = originTextList[i]; + //dataGridView1.Rows[i].Cells[1].Value = formatTextList[i]; + } + } + } +} diff --git a/ExcelToChart/Form_DateFormat.resx b/ExcelToChart/Form_DateFormat.resx new file mode 100644 index 0000000000000000000000000000000000000000..81622a893c28b5a1edf50d9fb96808f339954ff3 --- /dev/null +++ b/ExcelToChart/Form_DateFormat.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/ExcelToChart/Form_SelectYearMonth.Designer.cs b/ExcelToChart/Form_SelectYearMonth.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..831895adbfed034f8ab0e962f339e3d51338e836 --- /dev/null +++ b/ExcelToChart/Form_SelectYearMonth.Designer.cs @@ -0,0 +1,105 @@ +namespace ExcelToChart +{ + partial class Form_SelectYearMonth + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.button_OK = new System.Windows.Forms.Button(); + this.button_Cancel = new System.Windows.Forms.Button(); + this.dateTimePicker_Year = new System.Windows.Forms.DateTimePicker(); + this.dateTimePicker_Month = new System.Windows.Forms.DateTimePicker(); + this.SuspendLayout(); + // + // button_OK + // + this.button_OK.Location = new System.Drawing.Point(149, 192); + this.button_OK.Name = "button_OK"; + this.button_OK.Size = new System.Drawing.Size(75, 23); + this.button_OK.TabIndex = 2; + this.button_OK.Text = "确定"; + this.button_OK.UseVisualStyleBackColor = true; + this.button_OK.Click += new System.EventHandler(this.button_OK_Click); + // + // button_Cancel + // + this.button_Cancel.Location = new System.Drawing.Point(308, 192); + this.button_Cancel.Name = "button_Cancel"; + this.button_Cancel.Size = new System.Drawing.Size(75, 23); + this.button_Cancel.TabIndex = 3; + this.button_Cancel.Text = "取消"; + this.button_Cancel.UseVisualStyleBackColor = true; + this.button_Cancel.Click += new System.EventHandler(this.button_Cancel_Click); + // + // dateTimePicker_Year + // + this.dateTimePicker_Year.CustomFormat = "yyyy"; + this.dateTimePicker_Year.Font = new System.Drawing.Font("Microsoft YaHei", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.dateTimePicker_Year.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker_Year.Location = new System.Drawing.Point(105, 68); + this.dateTimePicker_Year.Name = "dateTimePicker_Year"; + this.dateTimePicker_Year.ShowUpDown = true; + this.dateTimePicker_Year.Size = new System.Drawing.Size(119, 43); + this.dateTimePicker_Year.TabIndex = 4; + this.dateTimePicker_Year.ValueChanged += new System.EventHandler(this.dateTimePicker_Year_ValueChanged); + // + // dateTimePicker_Month + // + this.dateTimePicker_Month.CustomFormat = "MM"; + this.dateTimePicker_Month.Font = new System.Drawing.Font("Microsoft YaHei", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.dateTimePicker_Month.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker_Month.Location = new System.Drawing.Point(293, 68); + this.dateTimePicker_Month.Name = "dateTimePicker_Month"; + this.dateTimePicker_Month.RightToLeftLayout = true; + this.dateTimePicker_Month.ShowUpDown = true; + this.dateTimePicker_Month.Size = new System.Drawing.Size(124, 43); + this.dateTimePicker_Month.TabIndex = 5; + this.dateTimePicker_Month.ValueChanged += new System.EventHandler(this.dateTimePicker_Month_ValueChanged); + // + // Form_SelectYearMonth + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(524, 264); + this.Controls.Add(this.dateTimePicker_Month); + this.Controls.Add(this.dateTimePicker_Year); + this.Controls.Add(this.button_Cancel); + this.Controls.Add(this.button_OK); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.Name = "Form_SelectYearMonth"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Text = "Form_SelectYearMonth"; + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button button_OK; + private System.Windows.Forms.Button button_Cancel; + private System.Windows.Forms.DateTimePicker dateTimePicker_Year; + private System.Windows.Forms.DateTimePicker dateTimePicker_Month; + } +} \ No newline at end of file diff --git a/ExcelToChart/Form_SelectYearMonth.cs b/ExcelToChart/Form_SelectYearMonth.cs new file mode 100644 index 0000000000000000000000000000000000000000..cd50daa474988c30919c39a5e8afa0b81f018bc0 --- /dev/null +++ b/ExcelToChart/Form_SelectYearMonth.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class Form_SelectYearMonth : Form + { + public DateTime dateTime { get; set; } + + public Form_SelectYearMonth() + { + InitializeComponent(); + } + + public Form_SelectYearMonth(DateTime dt) + { + dateTime = dt; + InitializeComponent(); + + dateTimePicker_Year.Value = dt; + dateTimePicker_Month.Value = dt; + Console.WriteLine(dt); + } + + private void button_OK_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void button_Cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void dateTimePicker_Year_ValueChanged(object sender, EventArgs e) + { + int yyyy = dateTimePicker_Year.Value.Year; + int MM = dateTimePicker_Month.Value.Month; + dateTime = new DateTime(yyyy, MM, 1); + } + + private void dateTimePicker_Month_ValueChanged(object sender, EventArgs e) + { + int yyyy = dateTimePicker_Year.Value.Year; + int MM = dateTimePicker_Month.Value.Month; + dateTime = new DateTime(yyyy, MM, 1); + } + } +} diff --git a/ExcelToChart/Form_SelectYearMonth.resx b/ExcelToChart/Form_SelectYearMonth.resx new file mode 100644 index 0000000000000000000000000000000000000000..1af7de150c99c12dd67a509fe57c10d63e4eeb04 --- /dev/null +++ b/ExcelToChart/Form_SelectYearMonth.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ExcelToChart/Form_SheetSelect.Designer.cs b/ExcelToChart/Form_SheetSelect.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..000c5da2650c6cf9232796ddc977efabe5c57639 --- /dev/null +++ b/ExcelToChart/Form_SheetSelect.Designer.cs @@ -0,0 +1,226 @@ +namespace ExcelToChart +{ + partial class Form_SheetSelect + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.SheetName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.YearMonth = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Process = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.button_end_ok = new System.Windows.Forms.Button(); + this.button_end_cancel = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.button_select_all = new System.Windows.Forms.Button(); + this.button_disselect_all = new System.Windows.Forms.Button(); + this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); + this.button_guess_year_month = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.SheetName, + this.YearMonth, + this.Process}); + this.dataGridView1.Location = new System.Drawing.Point(12, 12); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowTemplate.Height = 23; + this.dataGridView1.Size = new System.Drawing.Size(540, 426); + this.dataGridView1.TabIndex = 0; + this.dataGridView1.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseClick); + this.dataGridView1.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView1_CellMouseDoubleClick); + // + // SheetName + // + this.SheetName.HeaderText = "SheetName"; + this.SheetName.Name = "SheetName"; + // + // YearMonth + // + this.YearMonth.HeaderText = "YearMonth"; + this.YearMonth.Name = "YearMonth"; + // + // Process + // + this.Process.HeaderText = "Process"; + this.Process.Name = "Process"; + this.Process.Resizable = System.Windows.Forms.DataGridViewTriState.True; + this.Process.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; + // + // button_end_ok + // + this.button_end_ok.Location = new System.Drawing.Point(619, 322); + this.button_end_ok.Name = "button_end_ok"; + this.button_end_ok.Size = new System.Drawing.Size(119, 33); + this.button_end_ok.TabIndex = 1; + this.button_end_ok.Text = "确定"; + this.button_end_ok.UseVisualStyleBackColor = true; + this.button_end_ok.Click += new System.EventHandler(this.button_end_ok_Click); + // + // button_end_cancel + // + this.button_end_cancel.Location = new System.Drawing.Point(619, 380); + this.button_end_cancel.Name = "button_end_cancel"; + this.button_end_cancel.Size = new System.Drawing.Size(119, 33); + this.button_end_cancel.TabIndex = 2; + this.button_end_cancel.Text = "取消"; + this.button_end_cancel.UseVisualStyleBackColor = true; + this.button_end_cancel.Click += new System.EventHandler(this.button_end_cancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(617, 256); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(113, 12); + this.label1.TabIndex = 3; + this.label1.Text = "月份解析正则表达式"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(619, 283); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(100, 21); + this.textBox1.TabIndex = 4; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(619, 223); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(100, 21); + this.textBox2.TabIndex = 6; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(617, 196); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(113, 12); + this.label2.TabIndex = 5; + this.label2.Text = "年份解析正则表达式"; + // + // button_select_all + // + this.button_select_all.Location = new System.Drawing.Point(585, 12); + this.button_select_all.Name = "button_select_all"; + this.button_select_all.Size = new System.Drawing.Size(75, 23); + this.button_select_all.TabIndex = 7; + this.button_select_all.Text = "全选"; + this.button_select_all.UseVisualStyleBackColor = true; + this.button_select_all.Click += new System.EventHandler(this.button_select_all_Click); + // + // button_disselect_all + // + this.button_disselect_all.Location = new System.Drawing.Point(678, 12); + this.button_disselect_all.Name = "button_disselect_all"; + this.button_disselect_all.Size = new System.Drawing.Size(75, 23); + this.button_disselect_all.TabIndex = 8; + this.button_disselect_all.Text = "全不选"; + this.button_disselect_all.UseVisualStyleBackColor = true; + this.button_disselect_all.Click += new System.EventHandler(this.button_disselect_all_Click); + // + // dateTimePicker1 + // + this.dateTimePicker1.CustomFormat = "yyyy-MM"; + this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom; + this.dateTimePicker1.Location = new System.Drawing.Point(585, 172); + this.dateTimePicker1.Name = "dateTimePicker1"; + this.dateTimePicker1.Size = new System.Drawing.Size(200, 21); + this.dateTimePicker1.TabIndex = 9; + // + // button_guess_year_month + // + this.button_guess_year_month.Location = new System.Drawing.Point(619, 112); + this.button_guess_year_month.Name = "button_guess_year_month"; + this.button_guess_year_month.Size = new System.Drawing.Size(75, 23); + this.button_guess_year_month.TabIndex = 10; + this.button_guess_year_month.Text = "月份猜想"; + this.button_guess_year_month.UseVisualStyleBackColor = true; + this.button_guess_year_month.Click += new System.EventHandler(this.button_guess_year_month_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(561, 69); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(227, 12); + this.label3.TabIndex = 11; + this.label3.Text = "双击YearMonth列的单元格, 指定年月信息"; + // + // Form_SheetSelect + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.label3); + this.Controls.Add(this.button_guess_year_month); + this.Controls.Add(this.dateTimePicker1); + this.Controls.Add(this.button_disselect_all); + this.Controls.Add(this.button_select_all); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Controls.Add(this.button_end_cancel); + this.Controls.Add(this.button_end_ok); + this.Controls.Add(this.dataGridView1); + this.Name = "Form_SheetSelect"; + this.Text = "Form_SheetSelect"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form_SheetSelect_FormClosing); + this.Load += new System.EventHandler(this.Form_SheetSelect_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView1; + private System.Windows.Forms.DataGridViewTextBoxColumn SheetName; + private System.Windows.Forms.DataGridViewTextBoxColumn YearMonth; + private System.Windows.Forms.DataGridViewCheckBoxColumn Process; + private System.Windows.Forms.Button button_end_ok; + private System.Windows.Forms.Button button_end_cancel; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button_select_all; + private System.Windows.Forms.Button button_disselect_all; + private System.Windows.Forms.DateTimePicker dateTimePicker1; + private System.Windows.Forms.Button button_guess_year_month; + private System.Windows.Forms.Label label3; + } +} \ No newline at end of file diff --git a/ExcelToChart/Form_SheetSelect.cs b/ExcelToChart/Form_SheetSelect.cs new file mode 100644 index 0000000000000000000000000000000000000000..94cd702a8b297702eeb4d7967d9b193edcd466bb --- /dev/null +++ b/ExcelToChart/Form_SheetSelect.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class Form_SheetSelect : Form + { + Form1 mainForm; + + public List originSheetNames { get; set; } + public List selectedSheetNames { get; set; } + + public List selectedSheetYearMonth { get; set; } + + public Form_SheetSelect() + { + InitializeComponent(); + + } + + public Form_SheetSelect(List sheetNames) + { + originSheetNames = sheetNames; + InitializeComponent(); + } + + private void button_end_ok_Click(object sender, EventArgs e) + { + // 检查年月列, 如果选中的有重复, 不退出 + Console.WriteLine("button_end_ok_Click"); + selectedSheetNames = new List(); + + foreach (DataGridViewRow dgvr in dataGridView1.Rows) + { + if (dgvr.Cells[2] is DataGridViewCheckBoxCell) + { + if ((bool)((DataGridViewCheckBoxCell)dgvr.Cells[2]).FormattedValue == true) + { + Console.WriteLine(dgvr.Cells[0].Value.ToString()); + selectedSheetNames.Add(dgvr.Cells[0].Value.ToString()); + } + } + } + + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void button_end_cancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + private void Form_SheetSelect_Load(object sender, EventArgs e) + { + dataGridView1.DataSource = null; //每次打开清空内容 + + mainForm = (Form1)this.Owner; + + if(originSheetNames.Count <= 0) + { + MessageBox.Show("文件没有任何sheet"); + return; + } + + for(int i = 0; i < originSheetNames.Count; i++) + { + string sn = originSheetNames[i]; + Console.WriteLine(sn); + int index = this.dataGridView1.Rows.Add(); + this.dataGridView1.Rows[index].Cells[0].Value = sn; + + DateTime dt = DateTime.Today; + string yyyyMM = dt.ToString("yyyy-MM"); + this.dataGridView1.Rows[index].Cells[1].Value = yyyyMM; + this.dataGridView1.Rows[index].Cells[2].Value = false; + } + } + + private void Form_SheetSelect_FormClosing(object sender, FormClosingEventArgs e) + { + + } + + private void button_select_all_Click(object sender, EventArgs e) + { + for(int i = 0; i < dataGridView1.Rows.Count -1; i++) + { + DataGridViewRow dgvr = dataGridView1.Rows[i]; + if(dgvr != null) + { + dgvr.Cells[2].Value = true; + } + } + } + + private void button_disselect_all_Click(object sender, EventArgs e) + { + for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) + { + DataGridViewRow dgvr = dataGridView1.Rows[i]; + if (dgvr != null) + { + dgvr.Cells[2].Value = false; + } + } + } + + private void button_guess_year_month_Click(object sender, EventArgs e) + { + foreach (DataGridViewRow dgvr in dataGridView1.Rows) + { + if(dgvr.IsNewRow) + { + continue; + } + string sheetName = dgvr.Cells[0].Value.ToString(); + Console.WriteLine(sheetName+ " === " +Util.GuessMonth(sheetName).ToString()); + + } + } + + private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) + { + if(e.Button == MouseButtons.Right) + { + string s = string.Format("m-r click R{0} C{1}", e.RowIndex, e.ColumnIndex); + Console.WriteLine(s); + } + } + + private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) + { + string s = string.Format("m-2c click R{0} C{1}", e.RowIndex, e.ColumnIndex); + Console.WriteLine(s); + + if(e.ColumnIndex == 1) + { + string cellContent = (string)dataGridView1[e.ColumnIndex, e.RowIndex].Value; + DateTime dt = DateTime.ParseExact(cellContent, "yyyy-MM", CultureInfo.CurrentCulture, DateTimeStyles.None); + + Form_SelectYearMonth fsym = new Form_SelectYearMonth(dt); + fsym.Owner = this; + fsym.ShowDialog(); + + dt = fsym.dateTime; + Console.WriteLine(dt); + + cellContent = dt.ToString("yyyy-MM"); + dataGridView1[e.ColumnIndex, e.RowIndex].Value = cellContent; + + dataGridView1[e.ColumnIndex, e.RowIndex].Selected = false; + dataGridView1[e.ColumnIndex, e.RowIndex].Selected = true; + //dataGridView1[e.ColumnIndex, e.RowIndex]. + dataGridView1.EndEdit(); + } + + + } + } +} diff --git a/ExcelToChart/Form_SheetSelect.resx b/ExcelToChart/Form_SheetSelect.resx new file mode 100644 index 0000000000000000000000000000000000000000..e6b7f21869919e0aca317b9c92b1890600426b7b --- /dev/null +++ b/ExcelToChart/Form_SheetSelect.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ExcelToChart/NaturalCompare.cs b/ExcelToChart/NaturalCompare.cs new file mode 100644 index 0000000000000000000000000000000000000000..0a3c6c1fd72743842fa4105178c011d14da4c1c8 --- /dev/null +++ b/ExcelToChart/NaturalCompare.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ExcelToChart +{ + public class NaturalCompare : System.Collections.IComparer + { + public int Compare(object x, object y) + { + string s1 = (string)x; + string s2 = (string)y; + if (s1.Length > s2.Length) return 1; + if (s1.Length < s2.Length) return -1; + for (int i = 0; i < s1.Length; i++) + { + if (s1[i] > s2[i]) return 1; + if (s1[i] < s2[i]) return -1; + } + return 0; + } + } +} diff --git a/ExcelToChart/NaturalSortComparer .cs b/ExcelToChart/NaturalSortComparer .cs new file mode 100644 index 0000000000000000000000000000000000000000..6c01d452707103ad69d39d8ba184b3dfedcade37 --- /dev/null +++ b/ExcelToChart/NaturalSortComparer .cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ExcelToChart +{ + public class NaturalSortComparer : System.Collections.IComparer + { + + private System.Collections.Generic.Dictionary table; + + public NaturalSortComparer() + { + table = new System.Collections.Generic.Dictionary(); + } + + public void Dispose() + { + table.Clear(); + table = null; + } + + public int Compare(object x, object y) + { + System.Windows.Forms.DataGridViewRow DataGridViewRow1 = (System.Windows.Forms.DataGridViewRow)x; + System.Windows.Forms.DataGridViewRow DataGridViewRow2 = (System.Windows.Forms.DataGridViewRow)y; + + string xStr = DataGridViewRow1.Cells["Column1"].Value.ToString(); + string yStr = DataGridViewRow2.Cells["Column1"].Value.ToString(); + + + if (xStr == yStr) + { + return 0; + } + string[] x1, y1; + if (!table.TryGetValue(xStr, out x1)) + { + x1 = System.Text.RegularExpressions.Regex.Split(xStr.Replace(" ", ""), "([0-9]+)"); + table.Add(xStr, x1); + } + if (!table.TryGetValue(yStr, out y1)) + { + y1 = System.Text.RegularExpressions.Regex.Split(yStr.Replace(" ", ""), "([0-9]+)"); + table.Add(yStr, y1); + } + + for (int i = 0; i < x1.Length && i < y1.Length; i++) + { + if (x1[i] != y1[i]) + { + return PartCompare(x1[i], y1[i]); + } + } + if (y1.Length > x1.Length) + { + return 1; + } + else if (x1.Length > y1.Length) + { + return -1; + } + else + { + return 0; + } + } + + private static int PartCompare(string left, string right) + { + int x, y; + if (!int.TryParse(left, out x)) + { + return left.CompareTo(right); + } + + if (!int.TryParse(right, out y)) + { + return left.CompareTo(right); + } + + return x.CompareTo(y); + } + } +} diff --git a/ExcelToChart/Properties/Resources.Designer.cs b/ExcelToChart/Properties/Resources.Designer.cs index 4be4301d6d806cfaa30d696596759a583bc614ef..4d13a1c8bb49122e4fb45b43e35c4f0085be8c39 100644 --- a/ExcelToChart/Properties/Resources.Designer.cs +++ b/ExcelToChart/Properties/Resources.Designer.cs @@ -8,10 +8,10 @@ // //------------------------------------------------------------------------------ -namespace ExcelToChart.Properties -{ - - +namespace ExcelToChart.Properties { + using System; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -19,51 +19,43 @@ namespace ExcelToChart.Properties // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - + internal class Resources { + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { + internal Resources() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ExcelToChart.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { + internal static global::System.Globalization.CultureInfo Culture { + get { return resourceCulture; } - set - { + set { resourceCulture = value; } } diff --git a/ExcelToChart/Properties/Settings.Designer.cs b/ExcelToChart/Properties/Settings.Designer.cs index d4dea24f81c4a8093ea0182feebf0140536a9e00..a5d21800aef8e0e7f9328ddc9ad67c228500b491 100644 --- a/ExcelToChart/Properties/Settings.Designer.cs +++ b/ExcelToChart/Properties/Settings.Designer.cs @@ -34,5 +34,29 @@ namespace ExcelToChart.Properties { this["filePathLastTime"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string folderLastTime { + get { + return ((string)(this["folderLastTime"])); + } + set { + this["folderLastTime"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool ignoreEmptyRow { + get { + return ((bool)(this["ignoreEmptyRow"])); + } + set { + this["ignoreEmptyRow"] = value; + } + } } } diff --git a/ExcelToChart/Properties/Settings.settings b/ExcelToChart/Properties/Settings.settings index 9c914adf124455063fa5e70a8782c562a2f69a2f..3013664153cd3acdc89abc5ff0c96e644bbc338d 100644 --- a/ExcelToChart/Properties/Settings.settings +++ b/ExcelToChart/Properties/Settings.settings @@ -5,5 +5,11 @@ + + + + + False + \ No newline at end of file diff --git a/ExcelToChart/Util.cs b/ExcelToChart/Util.cs new file mode 100644 index 0000000000000000000000000000000000000000..b4d5805a0dc3887a440a1f41db8ea4cbf7e516e3 --- /dev/null +++ b/ExcelToChart/Util.cs @@ -0,0 +1,67 @@ +using NPOI.SS.UserModel; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ExcelToChart +{ + public partial class Form1 : Form + { + public void myPartialFunction() + { + Console.WriteLine("myPartialFunction run ok"); + } + } + + public static class Util + { + public static DateTime GuessMonth(string str) + { + DateTime dt = new DateTime(); + + return dt; + } + } + + public class SheetDataTable : DataTable + { + public DateTime YearMonth { get; set; } + + public DataGridView dataGridView { get; set; } + + public int dateColumnIndex { get; set; } + + public int numberColumnIndex { get; set; } + + public Dictionary rowToDayNumberMapping { get; set; } + + public SheetDataTable(ISheet npoiSheet) + { + this.TableName = npoiSheet.SheetName; + } + + public DataTable formatedTable + { + get + { + DataTable dt = new DataTable(); + dt.Columns.Add("Date"); + dt.Columns.Add("Number"); + + foreach(int k in rowToDayNumberMapping.Keys) + { + DataRow dr = dt.NewRow(); + dr["Date"] = string.Format("{0}-{1}-{2}", YearMonth.Year, YearMonth.Month, rowToDayNumberMapping[k]); + dr["Number"] = this.Rows[k][numberColumnIndex]; + } + return dt; + } + } + + + } +} diff --git a/ExcelToChart/app.config b/ExcelToChart/app.config index 109d58538b9f37ff355d002405f9516c25ae9ae7..2880205eefc387c13dc6d4b61120483770192a01 100644 --- a/ExcelToChart/app.config +++ b/ExcelToChart/app.config @@ -1,7 +1,7 @@ - + - +
@@ -10,6 +10,21 @@ + + + + + False + - \ No newline at end of file + + + + + + + + + + diff --git a/ExcelToChart/packages.config b/ExcelToChart/packages.config index ef9b3383e9b63093437e100c7894174a9249b2ab..5b6f880a8da0b59ca770509f7ac598f2b2a79afe 100644 --- a/ExcelToChart/packages.config +++ b/ExcelToChart/packages.config @@ -1,6 +1,9 @@  - - + + + + + \ No newline at end of file diff --git a/MakeReport/MakeReport.sln b/MakeReport/MakeReport.sln index 3903bf505b172818bc1c3f014d7868ce64b103fc..38231533b807679c8ceeb42454bf0b1a64a16409 100644 --- a/MakeReport/MakeReport.sln +++ b/MakeReport/MakeReport.sln @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MakeReport", "MakeReport.cs EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExcelToChart", "..\ExcelToChart\ExcelToChart.csproj", "{926D2FCE-CD99-498C-A002-5A2F6DC7B800}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataCombine", "..\DataCombine\DataCombine.csproj", "{7F22DE22-1A7D-4817-8A66-38179A5828C4}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {926D2FCE-CD99-498C-A002-5A2F6DC7B800}.Debug|Any CPU.Build.0 = Debug|Any CPU {926D2FCE-CD99-498C-A002-5A2F6DC7B800}.Release|Any CPU.ActiveCfg = Release|Any CPU {926D2FCE-CD99-498C-A002-5A2F6DC7B800}.Release|Any CPU.Build.0 = Release|Any CPU + {7F22DE22-1A7D-4817-8A66-38179A5828C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7F22DE22-1A7D-4817-8A66-38179A5828C4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7F22DE22-1A7D-4817-8A66-38179A5828C4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7F22DE22-1A7D-4817-8A66-38179A5828C4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE