Browse files

读取文件时,空格默认为“0”

  • Loading branch information...
1 parent 0723299 commit 7721b9a6dafde491e524e3fcf9fbbe83e3ee3d5e Advansil committed Apr 10, 2012
View
108 ExcelApplication/ExcelApplication/Form1.Designer.cs
@@ -1,32 +1,32 @@
-namespace ExcelApplication
-{
- partial class Form1
- {
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.IContainer components = null;
-
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows 窗体设计器生成的代码
-
- /// <summary>
- /// 设计器支持所需的方法 - 不要
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InitializeComponent()
+namespace ExcelApplication
+{
+ partial class Form1
+ {
+ /// <summary>
+ /// 必需的设计器变量。
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// 清理所有正在使用的资源。
+ /// </summary>
+ /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows 窗体设计器生成的代码
+
+ /// <summary>
+ /// 设计器支持所需的方法 - 不要
+ /// 使用代码编辑器修改此方法的内容。
+ /// </summary>
+ private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
@@ -215,7 +215,7 @@ private void InitializeComponent()
this.txtPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.txtPath.Location = new System.Drawing.Point(71, 443);
this.txtPath.Name = "txtPath";
- this.txtPath.Size = new System.Drawing.Size(370, 21);
+ this.txtPath.Size = new System.Drawing.Size(446, 21);
this.txtPath.TabIndex = 3;
this.txtPath.DoubleClick += new System.EventHandler(this.openToolStripMenuItem_Click);
//
@@ -227,17 +227,17 @@ private void InitializeComponent()
//
this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(494, 443);
+ this.comboBox1.Location = new System.Drawing.Point(576, 443);
this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(137, 20);
+ this.comboBox1.Size = new System.Drawing.Size(140, 20);
this.comboBox1.TabIndex = 4;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(447, 446);
+ this.label2.Location = new System.Drawing.Point(523, 446);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(47, 12);
this.label2.TabIndex = 5;
@@ -247,7 +247,7 @@ private void InitializeComponent()
//
this.btnLoadData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnLoadData.Enabled = false;
- this.btnLoadData.Location = new System.Drawing.Point(637, 441);
+ this.btnLoadData.Location = new System.Drawing.Point(722, 441);
this.btnLoadData.Name = "btnLoadData";
this.btnLoadData.Size = new System.Drawing.Size(75, 23);
this.btnLoadData.TabIndex = 6;
@@ -276,23 +276,23 @@ private void InitializeComponent()
this.ResumeLayout(false);
this.PerformLayout();
- }
-
- #endregion
-
- private System.Windows.Forms.MenuStrip menuStrip1;
- private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
+ }
+
+ #endregion
+
+ private System.Windows.Forms.MenuStrip menuStrip1;
+ private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem closeToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
- private System.Windows.Forms.DataGridView dataGridView1;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox txtPath;
- private System.Windows.Forms.OpenFileDialog openFileDialog1;
- private System.Windows.Forms.ComboBox comboBox1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Button btnLoadData;
+ private System.Windows.Forms.ToolStripMenuItem closeToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
+ private System.Windows.Forms.DataGridView dataGridView1;
+ private System.Windows.Forms.Label label1;
+ private System.Windows.Forms.TextBox txtPath;
+ private System.Windows.Forms.OpenFileDialog openFileDialog1;
+ private System.Windows.Forms.ComboBox comboBox1;
+ private System.Windows.Forms.Label label2;
+ private System.Windows.Forms.Button btnLoadData;
private System.Windows.Forms.ToolStripMenuItem toolToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem calculatorToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem codeToolStripMenuItem;
@@ -302,7 +302,7 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem statisticsToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem dateToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem ingotToolStripMenuItem;
- private System.Windows.Forms.ToolStripMenuItem cuttingToolStripMenuItem;
- }
-}
-
+ private System.Windows.Forms.ToolStripMenuItem cuttingToolStripMenuItem;
+ }
+}
+
View
61 ExcelApplication/ExcelApplication/Form1.cs
@@ -60,24 +60,7 @@ public bool dataTotal(int col)
{
for (int j = 5; j < columnCount; j++)
{
- if (string.IsNullOrEmpty(dataGridView1.Rows[i].Cells[j].Value.ToString()))
- {
- if (string.IsNullOrEmpty(dataGridView1.Rows[i + 1].Cells[j].Value.ToString()))
- {
- total = 0;
- }
- else
- { total = int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString()); }
- }
- else
- {
- if (string.IsNullOrEmpty(dataGridView1.Rows[i + 1].Cells[j].Value.ToString()))
- {
- total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString());
- }
- else
- { total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString()); }
- }
+ total = int.Parse(dataGridView1.Rows[i].Cells[j].Value.ToString()) + int.Parse(dataGridView1.Rows[i + 1].Cells[j].Value.ToString());
dataGridView1.Rows[i].Cells[j].Value = total.ToString();
}
dataGridView1.Rows.RemoveAt(i + 1);
@@ -90,7 +73,7 @@ public bool dataTotal(int col)
}
catch (Exception ex)
{
- MessageBox.Show("保存文件失败,详细信息:" + ex.Message);
+ MessageBox.Show(ex.Message, "Error");
return false;
}
return true;
@@ -104,6 +87,7 @@ private void closeToolStripMenuItem_Click(object sender, EventArgs e)
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
+ dlg.Filter = "Excel文件(*.xlsx)|*.xlsx|所有文件|*.*";
DialogResult dlgResult = dlg.ShowDialog();
if (dlgResult == DialogResult.OK)
{
@@ -138,9 +122,9 @@ private void btnLoadData_Click(object sender, EventArgs e)
{
ExcelLib.IExcel tmp = ExcelLib.PreExcel.GetExcel(txtPath.Text);
if (tmp == null)
- MessageBox.Show("文件不存在");
+ MessageBox.Show("File Not Found!", "Error");
if (!tmp.Open())
- MessageBox.Show("文件不能打开");
+ MessageBox.Show("File Not Found!", "Error");
tmp.CurrentSheetIndex = comboBox1.SelectedIndex;
int columnCount = tmp.GetColumnCount();
@@ -157,7 +141,14 @@ private void btnLoadData_Click(object sender, EventArgs e)
{
for (int j = 0; j < columnCount; j++)
{
- dataGridView1.Rows[i].Cells[j].Value = tmp.GetCellValue(i + 2, j + 1);
+ if (string.IsNullOrEmpty(tmp.GetCellValue(i + 2, j + 1)))
+ {
+ dataGridView1.Rows[i].Cells[j].Value = "0";
+ }
+ else
+ {
+ dataGridView1.Rows[i].Cells[j].Value = tmp.GetCellValue(i + 2, j + 1);
+ }
}
}
@@ -186,8 +177,7 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
{
ExcelLib.IExcel tmp = ExcelLib.PreExcel.GetExcel(txtPath.Text);
if (tmp == null)
- MessageBox.Show("文件不存在");
- tmp.CurrentSheetIndex = tmp.SheetCount;
+ MessageBox.Show("File Not Found!", "Error");
int columnCount = dataGridView1.ColumnCount;
int rowCount = dataGridView1.RowCount;
@@ -219,7 +209,7 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
if (tmp.Save(sheetName, array))
{
comboBox1.DataSource = GetSheetNames(txtPath.Text);
- MessageBox.Show("文件保存成功");
+ MessageBox.Show("File Save Success", "Information");
}
tmp.Close();
}
@@ -231,14 +221,11 @@ private void saveToolStripMenuItem1_Click(object sender, EventArgs e)
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
- Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
- e.RowBounds.Location.Y,
- dataGridView1.RowHeadersWidth - 4,
- e.RowBounds.Height);
+ Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y,
+ dataGridView1.RowHeadersWidth - 4, e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
- dataGridView1.RowHeadersDefaultCellStyle.Font,
- rectangle,
+ dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle,
dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
@@ -272,29 +259,31 @@ private void removeColumnToolStripMenuItem_Click(object sender, EventArgs e)
dataGridView1.Rows[i].Cells[2].Value = (rowValue[i].Length > 6) ? rowValue[i].Substring(0, 6) : rowValue[i];
}
dataGridView1.Columns[2].HeaderCell.Value = "铸锭编号";
- MessageBox.Show("删除了百分比和人员记录,整理出铸锭编号");
+ MessageBox.Show("Delete And Sort Records Success", "Information");
+
+ //dataGridView1.Columns[3].DefaultCellStyle.Format = "c";
}
private void dateToolStripMenuItem_Click(object sender, EventArgs e)
{
int selectCol = 3;
if (dataTotal(selectCol))
- MessageBox.Show("数据处理完毕");
+ MessageBox.Show("Processed Data Success", "Information");
}
private void ingotToolStripMenuItem_Click(object sender, EventArgs e)
{
int selectCol = 2;
if (dataTotal(selectCol))
- MessageBox.Show("数据处理完毕");
+ MessageBox.Show("Processed Data Success", "Information");
}
private void cuttingToolStripMenuItem_Click(object sender, EventArgs e)
{
int selectCol = 4;
if (dataTotal(selectCol))
- MessageBox.Show("数据处理完毕");
- }
+ MessageBox.Show("Processed Data Success", "Information");
+ }
}
}
View
2 ExcelApplication/ExcelApplication/Lib/ExcelLib.cs
@@ -19,7 +19,7 @@ public static IExcel GetExcel(string filePath)
//IExcel res = new Excel03(filePath.Trim());
//return res;
throw new Exception("不支持Excel97~2003版本文件");
- //return null;
+ //TODO:未写代码
}
else if (filePath.Trim().EndsWith("xlsx"))
{

0 comments on commit 7721b9a

Please sign in to comment.