难如果是word就自带了一繁简转换工具。可惜excel里面没有。不知道微软的人怎么想的。呵呵
解决方案 »
- 关于C# 附加SQL数据库的方法
- c#正则表达式1|323<>43|23<>23|45<>234|45
- 看别人的程序,比较一个字符串还用binary做比较,为什么?
- 如何在js中判断,选中的.jpg图片是Web所支持的.jpg图片????
- 窗体监视系统移动设备的插拨,并且确定是移动硬盘后得到控制权,向指定扇区位置写或读数据!
- 数据恢复问题
- 字符替换
- C#监听端口的windows服务,有点疑问请大家来看看,有代码框架,马上给分!~~
- TreeView节点右键点击,点完后自动跳回上次所选项
- SQLite+EF+Codefirst,已有数据表中添加一个not null的列,怎么设置默认值
- 入门级:问一个简单的问题
- 请问如何让主窗口能够时时反映对话框内的变化
Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic
Class StrConv1
Public Shared Sub Main(Args() As String)
If (Args.Length < 2)
Console.WriteLine("Usage Conv infilename outfilename.")
return
End If
Dim OutFile, InFile As String
InFile = Args(0)
OutFile = Args(1)
Dim fs As New System.IO.FileStream(InFile, IO.FileMode.Open)
Dim sr As New System.IO.StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"))
Dim sw As New System.IO.StreamWriter(OutFile, false, System.Text.Encoding.GetEncoding("gb2312"))
Dim buf(1024) As Char
Dim len As Integer = sr.Read(buf, 0, 1024)
Dim temp As String
While len > 0
temp = new String(buf, 0, len)
temp = StrConv(temp, VbStrConv.SimplifiedChinese)
sw.Write(temp)
len = sr.Read(buf, 0, 1024)
End While
sr.Close()
sw.Close()
End Sub
End Class
using System;
using System.IO;
using System.Text;
using Microsoft.VisualBasic;
class StrConv1 {
public static void Main(String[] Args) {
if (Args.Length < 2) {
Console.WriteLine("Usage Conv infilename outfilename.");
return;
}
String InFile = Args[0];
String OutFile = Args[1];
FileStream fs = new FileStream(InFile, FileMode.Open);
StreamReader sr = new StreamReader(fs, System.Text.Encoding.GetEncoding("gb2312"));
StreamWriter sw = new StreamWriter(OutFile, false, System.Text.Encoding.GetEncoding("gb2312"));
char[] buf = new char[1024];
int len = sr.Read(buf, 0, 1024);
String temp;
while (len > 0) {
temp = new String(buf, 0, len);
temp = Strings.StrConv(temp, VbStrConv.SimplifiedChinese, 1033);
sw.Write(temp);
len = sr.Read(buf, 0, 1024);
}
sr.Close();
sw.Close();
}
}但必须这样编译:
先找到microsoft.visualbasic.dll这个文件所在的目录(和mscorlib.dll同一目录下),假设在c:\winnt\microsoft.net\framework\v1.1.4322\这个目录下,上面的程序存到文件名为yourfile.cs的文件,然后编译:
csc /r:c:\winnt\microsoft.net\framework\v1.1.4322\microsoft.visualbasic.dll yourfile.cs运行:yourfile test.txt result.txt就可以实现了,但前提条件是必须是文本文件的格式。
下面是一段例子代码:
string str1="娱乐";
string str2=Microsoft.VisualBasic.Strings.StrConv(str1,Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0);
MessageBox.Show(str2);
//str2 == "娛樂"
既然word自带了一繁简转换工具,页excel里面没有,那么为何不直接利用word自带了一繁简转换工具?
1.打开excel文件
2.Ctrl+A
3.Ctrl+C
4.打开Word
5.Ctrl+V
6.调用word自带的繁简转换工具
7.Ctrl+A
8.Ctrl+C
9.转到excel
10.Ctrl+A
11.Ctrl+V
呵呵,C#暂时留着作别的用途吧。
同意 xixigongzhu(夕夕公主)
2. 用程序實現: 如果是單純的excel文件(全部數據都是在cell里,沒有其它如文本框,controls)其實也可讀取excel文件後利用XiXiGongZhu,TheAres所說的文本轉換方式進行轉換
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.VisualBasic;namespace gb2big
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 24);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(56, 21);
this.button1.TabIndex = 0;
this.button1.Text = "gb2big";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(184, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(8, 80);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(184, 21);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(8, 136);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(184, 21);
this.textBox3.TabIndex = 3;
this.textBox3.Text = "";
//
// button2
//
this.button2.Location = new System.Drawing.Point(200, 80);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(56, 21);
this.button2.TabIndex = 4;
this.button2.Text = "big2gb";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(264, 165);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.textBox3,
this.textBox2,
this.textBox1,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
string temp1,temp2;
temp1=textBox1.Text;
//big to gb
if(temp1!="")
{
temp2=Strings.StrConv(temp1,Microsoft.VisualBasic.VbStrConv.TraditionalChinese,0);
textBox2.Text=temp2;
}
} private void button2_Click(object sender, System.EventArgs e)
{
//gb to big
if(textBox2.Text!=""){
string temp=Strings.StrConv(textBox2.Text,Microsoft.VisualBasic.VbStrConv.SimplifiedChinese,0);
textBox3.Text=temp;
}
}
}
}