【发布时间】:2015-01-31 12:43:42
【问题描述】:
我有一长串数字(例如 10000203005595000),当我将值传递给 excel 时,我有一个(例如 10000E^+10)值,C# 中的代码应该是什么来操作单元格格式/数字/类别/分数。我有一个特定的价值。请帮助我,谢谢:-)
这是我的程序:`
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;
using MySql.Data.MySqlClient;
using Microsoft.Office.Interop.Excel;
using System.Text.RegularExpressions;
namespace BIS
{
public partial class labDB : Form
{
System.Data.DataTable data;
public labDB()
{
InitializeComponent();
}
//this is my report generator using Excel
private void genReport_Click(object sender, EventArgs e)
{
saveFileDialog1.InitialDirectory = "C:";
saveFileDialog1.Title = "Save as Excel File";
saveFileDialog1.FileName = "Laboratory Department Inventory Report";
saveFileDialog1.Filter = "Excel Files(2003)|*.xls|Excel Files(2007)|*.xlsx|Excel Files(2010)|*.xlsx|Excel Files(2013)|*.xlsx";
if (saveFileDialog1.ShowDialog() != DialogResult.Cancel)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
ExcelApp.Application.Workbooks.Add(Type.Missing);
ExcelApp.Columns.ColumnWidth = 25;
for (int i = 1; i < dataGridViewLAB.Columns.Count + 1; i++)
{
ExcelApp.Cells[1, i] = dataGridViewLAB.Columns[i - 1].HeaderText;
}
for (int i = 0; i < dataGridViewLAB.Rows.Count; i++)
{
for (int j = 0; j < dataGridViewLAB.Columns.Count; j++)
{
ExcelApp.Cells[i + 2, j + 1] = dataGridViewLAB.Rows[i].Cells[j].Value.ToString();
}
}
ExcelApp.ActiveWorkbook.SaveCopyAs(saveFileDialog1.FileName.ToString());
ExcelApp.ActiveWorkbook.Saved = true;
ExcelApp.Quit();
}
}
}
}
【问题讨论】:
标签: c# excel visual-studio-2010