C# 读取Excel的剪贴板
来源:互联网 发布:人工智能行业 编辑:程序博客网 时间:2024/05/21 09:35
1. Form1.Designer.cs, 创建winform应用程序,并在form1中替添加一个button 和一个richtext box:
namespace WindowsFormsApplication1{ partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.button1 = new System.Windows.Forms.Button(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(12, 12); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 0; this.button1.Text = "read"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // richTextBox1 // this.richTextBox1.Location = new System.Drawing.Point(12, 60); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(268, 201); this.richTextBox1.TabIndex = 1; this.richTextBox1.Text = ""; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.richTextBox1); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.RichTextBox richTextBox1; }}
2. 给button 加上click 事件
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication1{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.richTextBox1.Text = ""; try { var fmt_csv = System.Windows.Forms.DataFormats.CommaSeparatedValue; //read the CSV var dataobject = System.Windows.Forms.Clipboard.GetDataObject(); var stream = (System.IO.Stream)dataobject.GetData(fmt_csv); var enc = System.Text.Encoding.GetEncoding(1252); var reader = new System.IO.StreamReader(stream, enc); string data_csv = reader.ReadToEnd(); this.richTextBox1.AppendText(data_csv); //read the Unicode String string data_string = System.Windows.Forms.Clipboard.GetText(); this.richTextBox1.AppendText(data_string); } catch(Exception ex) { } } }}
3. 启动应用程序
4. 打开一个Excel, 在其中输入一些测试数据,选中测试数据,按Ctrl +C
5. 点击read 按钮,效果如下:
- C# 读取Excel的剪贴板
- c#如何获取来自剪贴板的EXCEL复制的表格
- c#读取Excel的数据
- c# 读取excel的一系列问题
- c# 读取 Excel的内容
- C#读取Excel的方法
- C#读取Excel的方法
- C#中Excel文件的读取
- C#中Excel文件的读取
- C#中Excel文件的读取
- C#中Excel文件的读取
- C#中Excel文件的读取
- c# 读取excel应注意的问题
- 用c#读取Excel的方法
- C#读取Excel到DataSet的方法
- 读取Excel文档的c#程序
- C# 读取excel 文件的方法
- 编程笔记-C# 读取excel的数据
- 95epay支付通道种类:3D通道,实时非3D通道,高级延时非3D通道,高级实
- 用C#读取图片的EXIF信息的方法
- 内存池
- WebDriver使用指南(完整篇)
- input 控件默认值 点击时自动消失的实现
- C# 读取Excel的剪贴板
- mysql 同步配置
- C++类和接口的设计原则探讨
- Windows 7 exe/桌面图标 文件打开方式关联错误,图标全部显示错误,打开方式关联了非系统默认打开方式 修复方案
- 64位win7下面vs 2008和PLSQL同时连接oracle
- Area
- 需要作的总结
- 对面向对象设计原则的总结
- 电脑本地连接没有了,解决方法