c#操作Excel 一些问题 字符变为null解决方法
C#读取Excel遇到无法读取的解决方法:
1.在导入数据连接字符串中,将IMEX=1加入,“Provider=Microsoft.Jet.OLEDB.4.0;Data Source="C:\Data.xls";Extended Properties="Excel 8.0;HDR=Yes;IMEX=1; ”,这样就可以。
C#读取Excel需要注意的:
IMEX=1:混合模式
HDR=Yes; 是否让第一行作为列头
两者必须一起使用。
本以为这样就OK了。
但在实际使用过程中,这样设置还是不行,查阅了不少资料才发现,原来还有一个注册表里的信息需要修改,
这样带能让excel不再使用前8行的内容来确定该列的类型。
C#读取Excel之注册表修改内容如下:
在HKLM\Software\Microsoft\Jet\4.0\Engines\Excel有一个TypeGuessRows值,预设是8,表示会先读取前8列来决定每一个栏位的型态,所以如果前8列的资料都是数字,到了第9列以后出现的文字资料都会变成null,所以如果要解决这个问题,只要把TypeGuessRows机码值改成0,就可以解这个问题了!
相关文档:
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.comboBox2.Items.Clear();
switch(this.comboBox1.SelectedIndex)
  ......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
namespace WebApplication2
{
/// <summary>
/// XMLHelper XML文档操作管理器
&nb ......
创建一个Winform用户控件 UserControl1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace MyActiveT ......
private void MakeLegend(IActiveView activeView,IPageLayout pageLayout)
{
//定义图例UID对象
UID uid = new UIDClass();
&n ......