C# 折线图与导出Excel

qinggeer 2009-03-23 11:29:59
1 股票走势图是怎么做的?它是实时更新的,那要不停读取数据库。股票k线图,上面是曲线,下面是柱状图这种效果是怎么做的?请大家帮帮我。我不知道怎么入手。呵呵

2 winform里导出datagridview里的数据到excel里是怎么做的?网上是有很多这样的文章,可是我试来试去都出错。嗯 ,希望大家给我个可用的解决方案。呵呵。有的还说 直接从cvs中读取GetDataSetFromCSV,这个csv用来做什么?用它有什么好处?呵呵,望路过的高手帮帮我,分不够我再加.
...全文
820 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
outou 2009-04-01
  • 打赏
  • 举报
回复
有关于VB.NET的EXCEL自定义类http://bingning.net/VB/SOURCE/index.html#programing不知是否有帮助。
qinggeer 2009-04-01
  • 打赏
  • 举报
回复
.......
还没解决。自己顶。帮顶者也有分,大家帮帮我。
qinggeer 2009-03-29
  • 打赏
  • 举报
回复
自己顶,明天结贴。
zhoulehua 2009-03-26
  • 打赏
  • 举报
回复
4楼赞一个。
ranle01 2009-03-26
  • 打赏
  • 举报
回复
http://www.cnblogs.com/liran/archive/2009/03/13/1410849.html
将datatable导出到excel
zzxap 2009-03-26
  • 打赏
  • 举报
回复
网上的很多例子都是静态的,要跟数据库结合,必须把那些数组改为dataset数组
qinggeer 2009-03-26
  • 打赏
  • 举报
回复
再顶。解决了马上结贴。
qinggeer 2009-03-25
  • 打赏
  • 举报
回复
第一个还没解决,自己顶。
mawering 2009-03-24
  • 打赏
  • 举报
回复
学习一下!
qinggeer 2009-03-24
  • 打赏
  • 举报
回复
2楼的朋友说:通过web services实现 ?能具体点吗?谢谢。呵呵

谢谢楼上各位朋友,第二个问题解决了。

嗯,第一个还在试,接着问,顶上去,呵呵。
wuyq11 2009-03-23
  • 打赏
  • 举报
回复
通过web services实现
http://www.cnblogs.com/dahuzizyd/articles/621494.html
http://www.cnblogs.com/lauer0246/articles/1227217.html
typeof 2009-03-23
  • 打赏
  • 举报
回复
up
yagebu1983 2009-03-23
  • 打赏
  • 举报
回复
up....
浮生若梦丶 2009-03-23
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 blackwhole 的回复:]
楼主第一个问题,推荐一个开源的图表控件ZedGraph,实时更新的效率不错。


http://zedgraph.org/wiki/index.php?title=Main_Page

第二个问题网上有很多的例子了。各种方式都有。我就不献丑了。
[/Quote]
jlj84237485 2009-03-23
  • 打赏
  • 举报
回复
帮顶一下
blackwhole 2009-03-23
  • 打赏
  • 举报
回复
楼主第一个问题,推荐一个开源的图表控件ZedGraph,实时更新的效率不错。


http://zedgraph.org/wiki/index.php?title=Main_Page

第二个问题网上有很多的例子了。各种方式都有。我就不献丑了。
compleat 2009-03-23
  • 打赏
  • 举报
回复
参考只是参考
你还想copy啊
qinggeer 2009-03-23
  • 打赏
  • 举报
回复
自己顶。

错误 1 当前上下文中不存在名称“Missing”
总报这个错是为什么啊。
linaren 2009-03-23
  • 打赏
  • 举报
回复
读写excel文件
http://blog.csdn.net/linaren/archive/2009/03/23/4016724.aspx
xiezl07 2009-03-23
  • 打赏
  • 举报
回复
楼上的第二个问题可以给你参考一下
以下是功能函数源码
/// <summary>
/// 把DataGridView中的数据导入到EXCEL中,如果DataGridView具有分页的话,只能导入当前页面记录到EXCEL中
/// 导出成功返回true,导出失败返回false
/// </summary>
/// <param name="grid">dataGridView 对象</param>
/// <param name="fileName">文件保存文件名(含保存路径)</param>
/// <param name="ReportTitle">表的标题</param>
/// <param name="sheetName">表单名</param>
/// <param name="firstRow">自定义第一行数据</param>
/// <returns>导出成功返回true,否则返回false</returns>
/// <remarks>修改:2008-12-31 增加导出进度显示,作者-谢中涞</remarks>
public static bool ExportDataGridToExcel(System.Windows.Forms.DataGridView grid, string fileName,
string ReportTitle, string sheetName, string firstRow)
{
bool flag = false;
if (grid.Rows.Count == 0)
{
MessageBox.Show("没有数据可供导出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}

#region 构建进度条窗体
Form progressForm = new Form();
progressForm.FormBorderStyle = FormBorderStyle.None;
progressForm.ShowInTaskbar = false;
progressForm.StartPosition = FormStartPosition.CenterScreen;
progressForm.Size = new System.Drawing.Size(320, 50);
progressForm.TopMost = true;

Label lbText = new Label();
lbText.Text = "正在导出数据...";
lbText.AutoSize = false;
lbText.Location = new System.Drawing.Point(10, 1);
progressForm.Controls.Add(lbText);
ProgressBar pb = new ProgressBar();
pb.Size = new System.Drawing.Size(303, 23);
pb.Location = new System.Drawing.Point(5, 25);
progressForm.Controls.Add(pb);
progressForm.Show();
Application.DoEvents();
#endregion

if (fileName == null || fileName == "")
return false;
try
{
//创建Excel工作薄
Microsoft.Office.Interop.Excel.Application xlApp =
new Microsoft.Office.Interop.Excel.ApplicationClass();

int rowIndex = 3; //行起始索引
int colIndex = 0; //列起始索引
int colCount = 0; //列总数(可见)
for (int i = 0; i < grid.Columns.Count; i++)
{
if (!grid.Columns[i].Visible)
continue;
else
colCount++;
}
//创建Excel工作表
Microsoft.Office.Interop.Excel.Workbook xlBook =
xlApp.Workbooks.Add(true);

if (xlApp == null)
{
throw new Exception("EXCEL无法启动!");
}
Microsoft.Office.Interop.Excel.Worksheet sheet =
(Microsoft.Office.Interop.Excel.Worksheet)xlBook.ActiveSheet;
sheet.Name = sheetName;//转出表名
if (grid.Rows.Count > 0)
{
//合并第一行单元格--写表格标题
Microsoft.Office.Interop.Excel.Range rangeTitle =
xlApp.get_Range(xlApp.Cells[1, 1], xlApp.Cells[1, colCount]);
rangeTitle.MergeCells = true;
xlApp.ActiveCell.FormulaR1C1 = ReportTitle; //表标题
xlApp.ActiveCell.Font.Size = 18;
xlApp.ActiveCell.Font.Bold = true;

//合并第二行单元格--写表格备注信息
Microsoft.Office.Interop.Excel.Range rangeRemark =
xlApp.get_Range(xlApp.Cells[2, 1], xlApp.Cells[2, colCount]);
rangeRemark.MergeCells = true;
xlApp.Cells[2, 1] = firstRow; //第一行自定义数据
foreach (DataGridViewColumn colu in grid.Columns)
{
//----不转出隐藏列---
if (!colu.Visible)
continue;
colIndex = colIndex + 1;
xlApp.Cells[3, colIndex] = colu.HeaderText;
}
pb.Maximum = grid.Rows.Count;//进度条最大值
//得到的表所有行,赋值给单元格
for (int row = 0; row < grid.Rows.Count; row++)
{
pb.Value = row + 1; //当前进度
if (grid.Rows[row].IsNewRow)
continue;
rowIndex = rowIndex + 1;
colIndex = 0;
for (int col = 0; col < grid.Columns.Count; col++)
{
if (!grid.Columns[col].Visible)
continue;
colIndex = colIndex + 1;
if (grid.Rows[row].Cells[col].Value == null)
xlApp.Cells[rowIndex, colIndex] = "";
else
xlApp.Cells[rowIndex, colIndex] =
"'" + grid.Rows[row].Cells[col].Value.ToString().Trim();
}
}
}
progressForm.Close();
progressForm.Dispose();

xlApp.get_Range(xlApp.Cells[3, 1], xlApp.Cells[3, colIndex]).Font.Bold = true;
xlApp.get_Range(xlApp.Cells[3, 1], xlApp.Cells[rowIndex, colIndex]).Borders.LineStyle = 1;

xlApp.Cells.EntireColumn.AutoFit();
xlApp.Cells.VerticalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;
xlApp.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter;

xlBook.Saved = true;
sheet.SaveAs(fileName,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
Application.DoEvents();
xlApp.Visible = true;
//清理使用的com资源
System.Runtime.InteropServices.Marshal.ReleaseComObject(sheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
flag = true;
}
catch (Exception ex)
{
progressForm.Close();
progressForm.Dispose();
throw new Exception(ex.Message);
}
System.Diagnostics.Process.GetCurrentProcess().MinWorkingSet = new System.IntPtr(5);
return flag;
}
加载更多回复(1)

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧