c# wpf和winform有啥区别吗?wpf能使用串口吗
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# wpf和winform有啥区别吗?wpf能使用串口吗相关的知识,希望对你有一定的参考价值。
wpf中似乎没有serialPort空间,能实现串口功能吗?怎么实现呢?
参考技术A 亲,简单来讲winform能做的,wpf都能做,而且界面做的更好,更炫,wpf编辑程序界面可以向编辑html界面一样,wpf可以使用XAML语言编辑wpf程序的界面,winform则不能使用XAML。至于使用串口,wpf和winform的使用是一样的,因为他们的后台语言用的都是C#c# winform 报表打印
c#开发winform系统,怎么做报表、表单的打印。
比较简单点的 用户可以自己设置打印表单的样式。
看到过fastreport这个的,但是这个在c#中集成不上。
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ToExcelDemo
class ExportExcel
public static void ExportToExcel(System.Windows.Forms.DataGridView grdView)
int rowCount = grdView.Rows.Count;
int columnCount = grdView.Columns.Count;
if (rowCount == 0)
System.Windows.Forms.MessageBox.Show("没有数据可供导出...", "Prompt", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
return;
System.Windows.Forms.SaveFileDialog saveDlg = new System.Windows.Forms.SaveFileDialog();
saveDlg.Title = "导出文件保存路径";
saveDlg.Filter = "Excel files(*.xls)|*.xls";
saveDlg.FilterIndex = 0;
saveDlg.RestoreDirectory = true;
saveDlg.ShowDialog();
string fileName = saveDlg.FileName;
if (fileName.Length != 0)
System.Reflection.Missing miss = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Visible = false;//若是true,则在导出的时候会显示EXcel界面
if (excel == null)
System.Windows.Forms.MessageBox.Show("Excel无法启动!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return;
Microsoft.Office.Interop.Excel.Workbooks workBooks = (Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workBook = (Microsoft.Office.Interop.Excel.Workbook)workBooks.Add(miss);
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.ActiveSheet;
workSheet.Name = "Test";
excel.Cells[1, 1] = grdView.TopLeftHeaderCell.Value;
for (int i = 0; i < grdView.Columns.Count; i++)
excel.Cells[1, i + 2] = grdView.Columns[i].HeaderText.ToString();
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
excel.Cells[rowIndex + 2, 1] = grdView.Rows[rowIndex].HeaderCell.Value.ToString();
for (int colIndex = 0; colIndex < columnCount; colIndex++)
excel.Cells[rowIndex + 2, colIndex + 2] = grdView[colIndex,rowIndex].Value.ToString();
try
workBook.SaveCopyAs(fileName);
catch (Exception ex)
System.Windows.Forms.MessageBox.Show(ex.Message);
我做过一个 看看能不能给你点启发 参考技术A using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace
ToExcelDemo
class
ExportExcel
public
static
void
ExportToExcel(System.Windows.Forms.DataGridView
grdView)
int
rowCount
=
grdView.Rows.Count;
int
columnCount
=
grdView.Columns.Count;
if
(rowCount
==
0)
System.Windows.Forms.MessageBox.Show("没有数据可供导出...",
"Prompt",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
return;
System.Windows.Forms.SaveFileDialog
saveDlg
=
new
System.Windows.Forms.SaveFileDialog();
saveDlg.Title
=
"导出文件保存路径";
saveDlg.Filter
=
"Excel
files(*.xls)|*.xls";
saveDlg.FilterIndex
=
0;
saveDlg.RestoreDirectory
=
true;
saveDlg.ShowDialog();
string
fileName
=
saveDlg.FileName;
if
(fileName.Length
!=
0)
System.Reflection.Missing
miss
=
System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.ApplicationClass
excel
=
new
Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Application.Workbooks.Add(true);
excel.Visible
=
false;//若是true,则在导出的时候会显示EXcel界面
if
(excel
==
null)
System.Windows.Forms.MessageBox.Show("Excel无法启动!",
"Error",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error);
return;
Microsoft.Office.Interop.Excel.Workbooks
workBooks
=
(Microsoft.Office.Interop.Excel.Workbooks)excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook
workBook
=
(Microso
以上是关于c# wpf和winform有啥区别吗?wpf能使用串口吗的主要内容,如果未能解决你的问题,请参考以下文章