没搞过winform开发,请给个例子 小弟一直搞web开发,现在急做一个winform操作分析excel数据的小程序,只有几天的时限。excel简单的导入导出之前到是接触过,可windows application一直没搞过,谁有winform的例子,请分享一下,有操作excel的代码也好。[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.qqview.com/Dev/DotNet/200711317338.Html http://www.qqview.com/Dev/DotNet/200782115901.Html http://www.qqview.com/Dev/DotNet/200742812806.Html cs 程序比web还简单的排版窗体想怎么放就怎么放 怎么就没人再给下载地址了呢,谁能给个c/s的源码呀。简单的mis的就好呀,真不甘心就这样的结贴了 string path = Application.StartupPath + "\\" + "temp"; string sfilename = Application.StartupPath + "\\" + "temp" + "\\PrintXsSytj.xls"; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(sfilename)) { File.Delete(sfilename); } Stream dataFileStream = Erm.ShareManagement.ApplicationManagement.GetResourceStream("Erm.Resources.Excel.PrintXsSytj.xls"); byte[] Content = new byte[(int)dataFileStream.Length]; //将文件内容写入字节数组 dataFileStream.Read(Content, 0, Content.Length); //关闭文件流 dataFileStream.Close(); FileStream fs = new FileStream(sfilename, FileMode.CreateNew); fs.Write(Content, 0, Content.Length); fs.Close(); Excel.Application excel = new Excel.Application(); object oMissing = System.Reflection.Missing.Value; excel.Application.Workbooks.Open(sfilename, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); Excel.Workbook mybook = (Excel.Workbook)excel.ActiveWorkbook; Excel.Worksheet mysheet = (Excel.Worksheet)mybook.ActiveSheet; if (gridex.RowCount < 1) { return; } Double xj = 0; Double yb = 0; Double yl = 0; Double djq = 0; Double ys = 0; Double ss = 0; foreach (GridEXRow myrow in gridex.GetRows()) { try { if (myrow.RowType == RowType.GroupFooter) { return; } //选中格式化好的行 Excel.Range range = (Excel.Range)mysheet.Rows.get_Item(3, Type.Missing); range.Rows.Insert(Excel.XlInsertShiftDirection.xlShiftDown); //range.Rows.Insert(Excel.XlInsertShiftDirection.xlShiftToRight); //在第3行上插入一行,新插入的则始终为第3行 excel.Cells[3, 2] = myrow.Cells["柜组名称"].Value.ToString(); excel.Cells[3, 3] = myrow.Cells["现金"].Value.ToString(); excel.Cells[3, 4] = myrow.Cells["医保"].Value.ToString(); excel.Cells[3, 5] = myrow.Cells["银联"].Value.ToString(); excel.Cells[3, 6] = myrow.Cells["代金券"].Value.ToString(); excel.Cells[3, 7] = myrow.Cells["应收"].Value.ToString(); excel.Cells[3, 8] = myrow.Cells["实收"].Value.ToString(); xj += Convert.ToDouble(myrow.Cells["现金"].Value); yb += Convert.ToDouble(myrow.Cells["医保"].Value); yl += Convert.ToDouble(myrow.Cells["银联"].Value); djq += Convert.ToDouble(myrow.Cells["代金券"].Value); ys += Convert.ToDouble(myrow.Cells["应收"].Value); ss += Convert.ToDouble(myrow.Cells["实收"].Value); } catch (Exception ex) { MessageBox.Show(ex.Message); excel.Quit(); } } //开始日期 excel.Cells.Replace("{#SDATE#}", Sdate.ToString("yyyy年MM月dd日HH点mm分"), Type.Missing, Type.Missing, Type.Missing, Type.Missing); //结束日期 excel.Cells.Replace("{#EDATE#}", Edate.ToString("yyyy年MM月dd日HH点mm分"), Type.Missing, Type.Missing, Type.Missing, Type.Missing); //汇总信息 excel.Cells.Replace("{#XJ#}", xj, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#YB#}", yb, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#YL#}", yl, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#DJQ#}", djq, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#YS#}", ys, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#SS#}", ss, Type.Missing, Type.Missing, Type.Missing, Type.Missing); excel.Cells.Replace("{#FLWJ#}", flwj, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //预览后打印 excel.Visible = true; mybook.PrintPreview(1); //单据调整好后,不用预览直接打印,打印后直接退出 //mybook.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); //mybook.Close(0, Type.Missing, Type.Missing); //excel.Quit(); } catch (Exception ex) { MessageBox.Show("您的计算机没有安装EXCEL!" + "\n" + ex.Message); } 微软的官方网站有很多精典的例子,http://windowsclient.net/另外,在http://www.codeproject.com上也有不少针对具体知识点的例子。 怎么解决输入字符串的格式不正确 如何动态调用静态属性? C#中使用API函数的问题 在CSDN下了本AJAX,看不很懂 请教个小问题啊 这个linq语句怎么写? C#获取falsh文本解密求解密方法 类????(立即给分)实例 引用owc时出现“程序集生成失败 -- 引用的程序集“Interop.OWC10”没有强名称” how to use array in C# 关于如何将dataSEt中的多个DataTable合成一个表的问题 遇到dataset的难题,请高手请教!!急~~~~
排版窗体想怎么放就怎么放
string sfilename = Application.StartupPath + "\\" + "temp" + "\\PrintXsSytj.xls"; try
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
if (File.Exists(sfilename))
{
File.Delete(sfilename);
}
Stream dataFileStream = Erm.ShareManagement.ApplicationManagement.GetResourceStream("Erm.Resources.Excel.PrintXsSytj.xls"); byte[] Content = new byte[(int)dataFileStream.Length];
//将文件内容写入字节数组 dataFileStream.Read(Content, 0, Content.Length);
//关闭文件流
dataFileStream.Close(); FileStream fs = new FileStream(sfilename, FileMode.CreateNew); fs.Write(Content, 0, Content.Length);
fs.Close(); Excel.Application excel = new Excel.Application();
object oMissing = System.Reflection.Missing.Value;
excel.Application.Workbooks.Open(sfilename, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
Excel.Workbook mybook = (Excel.Workbook)excel.ActiveWorkbook;
Excel.Worksheet mysheet = (Excel.Worksheet)mybook.ActiveSheet;
if (gridex.RowCount < 1)
{
return;
}
Double xj = 0;
Double yb = 0;
Double yl = 0;
Double djq = 0;
Double ys = 0;
Double ss = 0; foreach (GridEXRow myrow in gridex.GetRows())
{
try
{
if (myrow.RowType == RowType.GroupFooter)
{
return;
} //选中格式化好的行
Excel.Range range = (Excel.Range)mysheet.Rows.get_Item(3, Type.Missing);
range.Rows.Insert(Excel.XlInsertShiftDirection.xlShiftDown);
//range.Rows.Insert(Excel.XlInsertShiftDirection.xlShiftToRight); //在第3行上插入一行,新插入的则始终为第3行 excel.Cells[3, 2] = myrow.Cells["柜组名称"].Value.ToString();
excel.Cells[3, 3] = myrow.Cells["现金"].Value.ToString();
excel.Cells[3, 4] = myrow.Cells["医保"].Value.ToString();
excel.Cells[3, 5] = myrow.Cells["银联"].Value.ToString();
excel.Cells[3, 6] = myrow.Cells["代金券"].Value.ToString();
excel.Cells[3, 7] = myrow.Cells["应收"].Value.ToString();
excel.Cells[3, 8] = myrow.Cells["实收"].Value.ToString();
xj += Convert.ToDouble(myrow.Cells["现金"].Value);
yb += Convert.ToDouble(myrow.Cells["医保"].Value);
yl += Convert.ToDouble(myrow.Cells["银联"].Value);
djq += Convert.ToDouble(myrow.Cells["代金券"].Value);
ys += Convert.ToDouble(myrow.Cells["应收"].Value);
ss += Convert.ToDouble(myrow.Cells["实收"].Value); }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
excel.Quit();
} } //开始日期
excel.Cells.Replace("{#SDATE#}", Sdate.ToString("yyyy年MM月dd日HH点mm分"), Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//结束日期
excel.Cells.Replace("{#EDATE#}", Edate.ToString("yyyy年MM月dd日HH点mm分"), Type.Missing, Type.Missing, Type.Missing, Type.Missing); //汇总信息
excel.Cells.Replace("{#XJ#}", xj, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#YB#}", yb, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#YL#}", yl, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#DJQ#}", djq, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#YS#}", ys, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#SS#}", ss, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excel.Cells.Replace("{#FLWJ#}", flwj, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//预览后打印
excel.Visible = true;
mybook.PrintPreview(1); //单据调整好后,不用预览直接打印,打印后直接退出
//mybook.PrintOut(Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//mybook.Close(0, Type.Missing, Type.Missing);
//excel.Quit();
}
catch (Exception ex)
{
MessageBox.Show("您的计算机没有安装EXCEL!" + "\n" + ex.Message);
}
http://windowsclient.net/
另外,在
http://www.codeproject.com
上也有不少针对具体知识点的例子。