C#控制输出excel文件。本机执行没问题,移到其他电脑报错

excel版本不同,我做的是用的Office2003的,移到了2007的电脑上报错。有没有办法可以让程序自动适应Office版本

3个回答

这个没办法,最好用同一版本,不同版本的office,com组件等应该会有一些区别。

可以考虑用流的形式来输出excel文件
我写的一个excle导出工具类 可以实现把datatable导出成excel,用流的形式来做,适合各种环境。

 using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Web;
using System.Reflection;
namespace Culture2.Util
{
    public class ExcelHelp
    {
        /// <summary>
        /// DataTable通过流导出Excel
        /// </summary>
        /// <param name="dt">要导出的datatable</param>
        /// <param name="fileName">保存文件名(例如:a.xls)</param>
                /// <param name="fileName">保存路径</param>
        /// <returns></returns>
        public static bool StreamExport(DataTable dt, string fileName, string savePath)
        {
            if (dt.Rows.Count > 65535) //总行数大于Excel的行数 
            {
                throw new Exception("预导出的数据总行数大于excel的行数");
            }
            if (string.IsNullOrEmpty(fileName)) return false;

            StringBuilder content = new StringBuilder();
            StringBuilder strtitle = new StringBuilder();
            content.Append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>");
            content.Append("<head><title></title><meta http-equiv='Content-Type' content=\"text/html; charset=gb2312\">");
            //注意:[if gte mso 9]到[endif]之间的代码,用于显示Excel的网格线,若不想显示Excel的网格线,可以去掉此代码
            content.Append("<!--[if gte mso 9]>");
            content.Append("<xml>");
            content.Append(" <x:ExcelWorkbook>");
            content.Append("  <x:ExcelWorksheets>");
            content.Append("   <x:ExcelWorksheet>");
            content.Append("    <x:Name>Sheet1</x:Name>");
            content.Append("    <x:WorksheetOptions>");
            content.Append("      <x:Print>");
            content.Append("       <x:ValidPrinterInfo />");
            content.Append("      </x:Print>");
            content.Append("    </x:WorksheetOptions>");
            content.Append("   </x:ExcelWorksheet>");
            content.Append("  </x:ExcelWorksheets>");
            content.Append("</x:ExcelWorkbook>");
            content.Append("</xml>");
            content.Append("<![endif]-->");
            content.Append("</head><body><table style='border-collapse:collapse;table-layout:fixed;'><tr>");
            for (int i = 0; i < dt.Columns.Count; i++)
                content.Append("<td><b>" + dt.Columns[i].ColumnName + "</b></td>");

            content.Append("</tr>\n");

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                content.Append("<tr>");
                for (int k = 0; k < dt.Columns.Count; k++)
                {
                    object obj = dt.Rows[j][k];
                    Type type = obj.GetType();
                    if (type.Name == "Int32" || type.Name == "Single" || type.Name == "Double" || type.Name == "Decimal")
                    {
                        double d = obj == DBNull.Value ? 0.0d : Convert.ToDouble(obj);
                        if (type.Name == "Int32" || (d - Math.Truncate(d) == 0))
                            content.AppendFormat("<td style='vnd.ms-excel.numberformat:#,##0'>{0}</td>", obj);
                        else
                            content.AppendFormat("<td style='vnd.ms-excel.numberformat:#,##0.00'>{0}</td>", obj);
                    }
                    else
                        content.AppendFormat("<td style='vnd.ms-excel.numberformat:@'>{0}</td>", obj);
                }
                content.Append("</tr>\n");
            }
            content.Append("</table></body></html>");
            content.Replace("&nbsp;", "");
            CreateExecl(fileName, content.ToString(), savePath);
            return true;
        }
        private static void CreateExecl(string saveName, string content, string SavePath)
        {
            if (!Directory.Exists(SavePath))
                Directory.CreateDirectory(SavePath);

            string savePath = SavePath + "\\" + saveName;

            if (!File.Exists(savePath))
            {
                using (FileStream fs = File.Create(savePath))
                {
                    byte[] arr = Encoding.GetEncoding("gb2312").GetBytes(content);
                    fs.Write(arr, 0, arr.Length);
                }
            }
        }

    }
}

使用方法:
先将你要导出的excel表格构建成一个datatable (datatable列名就是表头的列名称),可以直接使用sql语句来构造
然后调用以下方法:

  ExcelHelp.StreamExport(dt,"1.xls","c:\\");

就可以了

装个office 没那么费劲。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
客户端EXCEL输出报错
rn输出EXCEL自己测试是好的,拷贝EXE文件到另外一台电脑,输出EXCEL时报错:rn不能找到microsoft.office.interop.excel VERSION=11.0.0.0rn因为我引用的是这个,我看了客户端也是安装的EXCEL2003,是不是小版本号不对啊?rn这种情况是不是必须要打包安装才能运行?
vs2003编译报错,其他电脑运行vs2003没问题
1.编译时候错误的提示,如下rnrn正在编译...rnstdafx.cpprnf:\source\add_file\include\sys\cdefs.h(263):fatal error C1189: #error: "No function renaming possible"rnrn2.这是头文件的部分代码:rn[code=C/C++]#if defined(_KERNEL)rn#if defined(NO_KERNEL_RCSIDS)rn#undef __KERNEL_RCSIDrn#define __KERNEL_RCSID(_n, _s) /* nothing */rn#endif /* NO_KERNEL_RCSIDS */rn#endif /* _KERNEL */rnrn#if !defined(_STANDALONE) && !defined(_KERNEL)rn#ifdef __GNUC__rn#define __RENAME(x) ___RENAME(x)rn#elsern#ifdef __lint__rn#define __RENAME(x) __symbolrename(x)rn#elsern#error "No function renaming possible"rn#endif /* __lint__ */rn#endif /* __GNUC__ */rn#else /* _STANDALONE || _KERNEL */rn#define __RENAME(x) no renaming in kernel or standalone environmentrn#endif[/code]rnrn不知道为什么原因?求高手帮忙。。rn
用ADO远程联SQL2000,在本机执行程序没问题(本机装有SQL2000客户端),换在其他机器执行就报错???
pCn->Open("driver=SQL Server;Server=211.64.156.98;Initial Catalog=pubs;UID=sa;PWD=0829","","",adModeUnknown); rn
excel vba访问其他电脑上的excel文件的代码
Private Sub CommandButton1_Click()     Dim xlapp1 As Excel.Application     Dim xlbook1 As Excel.Workbook     Dim xlsheet1 As Excel.Worksheet     Dim xlapp2 As Excel.Application     Dim xlbook2 As
本机电脑里的 hosts 文件
修复git不能正确上传,提示权限问题 Git 使用中出现的错误 关于错误:ssh: Could not resolve hostname github.com: Name or service not known.fatal: Could
如何把本机的数据库文件移植到其他电脑
本人是菜鸟,请教各位高手。rn如何可以把mysql的数据库表移植出来,通过什么样的java代码可以插入到程序,然后在其他电脑都可以安装,运行。就好像用vc打包成exe,在哪台机子安装都好!!rnrnrn有什么书介绍代码的吗?我想自己找,但是不知道怎么提问好!!!希望大家给个提示我。。。
如何让其他电脑调用本机的WebService?
WebService里面写了2个传入值,在自己的电脑上打开WebService的页面时可以看到页面上的输入框,但如果换其他电脑调用我的这个页面的时候就看不到那两个输入框了,怎么办?要如何解决呢?
局域网其他电脑无法访问本机apache网页
wampserver(V3.0.6)运行很奇怪,绿标,"服务器离线-所有服务正常运行"rnapache(V2.4.23)httpd文件也把默认"require local"修改为"Require all granted"rn本机输入本机ip地址或localhost均可访问apache网页,但局域网内其他机子输入本机ip地址仍网页无法连接rn也ipv4协议也导入了LMHOSTS,导入为apache的httpd文件rn本着能自己解决不麻烦大伙的原则捣鼓了十几个小时,最后实在找不出原因了,望各位大触搭救[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/3.gif][/img]rn[img=https://img-bbs.csdn.net/upload/201610/26/1477463615_429090.png][/img][img=https://img-bbs.csdn.net/upload/201610/26/1477463619_588566.png][/img]rn在线等,挺急0.0~rn
C#控制电脑并口
并非我写的,是从CodeProject上面下载的,感觉以后可能有用,便上传至此备份
C#控制电脑关机
在窗体上添加一个按钮button1,在按钮的单击事件上添加代码System.Diagnostics.Process.Start(&quot;cmd.exe&quot;,&quot;/cshutdown -s -t 1000&quot;); 这是一个定时关机代码,后面的1000表示倒计时1000秒后关机,如果要立即关机,把1000改为0就可以立即关机...
急..Socket C# 文件执行报错
请教各位高手:为什么我用VS 写了一个C# Socket程序 .在VS的Debug运行时没有任何问题.rnrn在开发机器运行debug目录下的exe文件也没有问题.但把这个文件拷到另一台机器上后,只要一有客户端连接就报错.提示,NullReferenceException;rnrn请高手帮忙看看,用VS写完是不是不能直接用EXE文件,要做什么打包操作吗,谢谢!
[c#控制电脑进程]
我们能不能用c#代码区控制电脑当前的进程,比如控制windows任务管理器的进程...rn如果可以的话,给个代码rn谢谢了rn或者提供个思想也行呀
C#执行EXE文件与输出消息的提取
简介:有时候会需要在c#特别是WPF环境下调用其他的程序,这类型的程序以命令行为执行环境,这里就说明下如何调用exe并传递参数   一般有两种方法,一种是直接调用exe程序并执行,另一种是调用cmd.exe然后通过输入的方式来执行指定的程序,前者虽然直接但是有时候不能读出输出的信息   因此这里我推荐使用第二个方法,使用异步的方式来创建cmd.exe进程,然后调用我们所需要的程序   ...
C#执行sqcmd.ExecuteNonQuery() 报错
tryrn rn DataConnect().Open();//打开数据库rn SqlCommand sqcmd = new SqlCommand();rn sqcmd.Connection = DataConnect();rn sqcmd.CommandTimeout = 100;rn foreach (Packagingmanage item in lp)rn rn sqcmd.CommandText = "insert into tb_outofstorage (s_deptId,s_warehouseId,s_labelNumber) values ('1','1','" + item.S_labelNumber + "')";rn sqcmd.ExecuteNonQuery();rn rn rn catch (Exception ex)rn rnrn throw ex;rn rn finallyrn rn DataConnect().Close();rn rnrnrn错误提示:未处理 System.InvalidOperationExceptionrn Message="ExecuteReader requires an open and available Connection. The connection's current state is Closed."rn StackTrace:rn 位于 System.Data.SqlClient.SqlCommand.ValidateCommand()rn 位于 System.Data.SqlClient.SqlCommand.ExecuteReader()rn 位于 System.Data.SqlClient.SqlCommand.ExecuteScalar()rn 位于 XC2901PDA.Sample.DataServer.InsertIntoLibrary()rn 位于 XC2901PDA.Sample.WarehouseFrom.button2_Click()rn 位于 System.Windows.Forms.Control.OnClick()rn 位于 System.Windows.Forms.Button.OnClick()rn 位于 System.Windows.Forms.ButtonBase.WnProc()rn 位于 System.Windows.Forms.Control._InternalWnProc()rn 位于 Microsoft.AGL.Forms.EVL.EnterModalDialog()rn 位于 System.Windows.Forms.Form.ShowDialog()rn 位于 XC2901PDA.Sample.LoginLibrary.btnLogin_Click()rn 位于 System.Windows.Forms.Control.OnClick()rn 位于 System.Windows.Forms.Button.OnClick()rn 位于 System.Windows.Forms.ButtonBase.WnProc()rn 位于 System.Windows.Forms.Control._InternalWnProc()rn 位于 Microsoft.AGL.Forms.EVL.EnterMainLoop()rn 位于 System.Windows.Forms.Application.Run()rn 位于 XC2901PDA.Sample.Program.Main()rn InnerException: rnrn
C#数据库执行报错
我执行的是最简单的SQL语句,我现在有两个库,一个是客户的,一个是我自己建的,用客户的数据库就会报如下图的错误,但是用我自己的数据库就不会,现在可以知道应该是数据库的问题,但不知道问题在哪?应该怎么解决?[img=https://img-bbs.csdn.net/upload/201508/10/1439205407_273506.png][/img]还请各位大神帮忙解决一下,红色框中的代码就是执行报错的地方。
C#执行Oracle存储过程报错
参数数量没错,类型没错rn错误是:rnORA-06550: line 1, column 7:rnrnPLS-00306: wrong number or types of arguments in call to 'SP_ADDORDERS'rnrnORA-06550: line 1, column 7:rnrn存储过程是:rncreate or replace PROCEDURE SP_ADDORDERS ----新建委托单rn (rn P_ORDERNUM IN NVARCHAR2,rn P_EXPERINAME IN NVARCHAR2,rn P_CONTRACTNUM IN NVARCHAR2,rn P_BATCHNUM IN NVARCHAR2,rn P_BALENUM IN NVARCHAR2,rn P_SPECIMENNAME IN NVARCHAR2,rn P_PARTNUM IN NVARCHAR2,rn P_SAMPLEAMOUNT IN NUMBER,rn P_FACILITYNAME IN NVARCHAR2,rn P_FACILITYMODELNUM IN NVARCHAR2,rn P_FACILITYCODE IN NVARCHAR2,rn P_FACILITYINDATE IN NVARCHAR2,rn P_TESTTYPE IN NVARCHAR2,rn P_TESTINGPROJECT IN NVARCHAR2,rn P_TESTBASIS IN NVARCHAR2,rn P_ENTRUSTREQUIRE IN NVARCHAR2,rn P_ENTRUSTUNITS IN NVARCHAR2,rn P_ENTRUSTADDRESS IN NVARCHAR2,rn P_ENTRUSCONTACTINFO IN NVARCHAR2,rn P_DEPARTMENT IN NVARCHAR2,rn P_ISRESERVEDSAMPLE IN NVARCHAR2,rn P_RESERVEDDATE IN DATE,rn P_ORDERSTATUS IN NVARCHAR2,rn P_REMARK IN NVARCHAR2,rn P_ExperimentType IN NUMBER,rn P_TestEngineer in NVARCHAR2,rn P_CREATETIME IN DATE,rn P_RECEIVEDATE IN DATE,rn retValue OUT NUMBER --返回值 0:增加失败 1:插入成功 2.单号已存在rn rn )rnISrn colNUM NUMBER;rnBEGINrn SELECT COUNT (*)rn INTO colNUMrn FROM T_BUSINESS_ORDERSrn WHERE ORDERNUM = P_ORDERNUM;rnrn IF colNUM = 0rn THENrn INSERT INTO T_BUSINESS_ORDERS (ID,rn ORDERNUM,rn EXPERINAME,rn CONTRACTNUM,rn BATCHNUM,rn BALENUM,rn SPECIMENNAME,rn PARTNUM,rn SAMPLEAMOUNT,rn FACILITYNAME,rn FACILITYMODELNUM,rn FACILITYCODE,rn FACILITYINDATE,rn TESTTYPE,rn TESTINGPROJECT,rn TESTBASIS,rn ENTRUSTREQUIRE,rn ENTRUSTUNITS,rn ENTRUSTADDRESS,rn ENTRUSCONTACTINFO,rn DEPARTMENT,rn ISRESERVEDSAMPLE,rn RESERVEDDATE,rn ORDERSTATUS,rn REMARK,rn EXPERIMENTTYPE,rn TESTENGINEER,rn CREATETIME,rn RECEIVEDATE)rn VALUES (SEQ_BUSINESS_ORDERSID.NEXTVAL,rn P_ORDERNUM,rn P_EXPERINAME,rn P_CONTRACTNUM,rn P_BATCHNUM,rn P_BALENUM,rn P_SPECIMENNAME,rn P_PARTNUM,rn P_SAMPLEAMOUNT,rn P_FACILITYNAME,rn P_FACILITYMODELNUM,rn P_FACILITYCODE,rn P_FACILITYINDATE,rn P_TESTTYPE,rn P_TESTINGPROJECT,rn P_TESTBASIS,rn P_ENTRUSTREQUIRE,rn P_ENTRUSTUNITS,rn P_ENTRUSTADDRESS,rn P_ENTRUSCONTACTINFO,rn P_DEPARTMENT,rn P_ISRESERVEDSAMPLE,rn P_RESERVEDDATE,rn P_ORDERSTATUS,rn P_REMARK,rn P_ExperimentType,rn P_TestEngineer,rn P_CREATETIME,rn P_RECEIVEDATE);rnrn IF (SQL%ROWCOUNT) > 0rn THENrn retValue := 1;rn ELSErn retValue := 0;rn END IF;rnrn COMMIT;rn ELSErn retValue := 2;rn END IF;rnrn COMMIT;rnEND SP_ADDORDERS;
在C#中创建一个Excel文件报错
请问各位:rn在C#中我要创建一个Excel文件,用如下代码:rnrnExcel.Application myExcel = new Excel.Application( ) ;rnrn老是报错: ---> "拒绝访问"rnrn要求授予 ASP.NET 对文件的写访问权,可是我授予了,还是不行,请问怎么解决啊?rn
C#用NPOIE创建Excel文件报错
[img=https://img-bbs.csdn.net/upload/201706/02/1496386579_939145.png][/img]
C#中输出EXCEL必须的的DLL文件
EXCEL DLL 使用方法:右击项目的引用-》添加-》添加文件
执行sh文件报错
我的aaa.sh文件如下:rn#!/bin/shrnORACLE_HOME=/oracle/products/10.2/dbrnexport ORACLE_HOMErnORACLE_SID=stdmrnexport ORACLE_SIDrn/oracle/products/10.2/db/bin/sqlplus username/password@stdm <
sh文件执行报错
执行时提示权限不够,处理方法:使用chmod命令为该文件增加x权限 [root@CentOS sh]# ./helloworld.sh -bash: ./helloworld.sh: 权限不够 执行时提示:没有那个文件或目录 [root@CentOS sh]# ./helloworld.sh -bash: ./helloworld.sh: bin/sh: bad interpr
源文件、执行文件和输出文件
Windows控制台程序。
如何生成本机excel文件
.net是否可以实现如下功能:将网页上表格的内容生成excel文件,并保存在本机的目录下,而不是服务器的目录下?rn
C# 调用Excel报错
VS2008 C#开发的软件,调用Office读取Excel时发生如下错误:rnrn[color=#FF0000]System.Runtime.InteropServices.COMException (0x80040154): 检索 COM 类工厂中 CLSID 为 00024500-0000-0000-C000-000000000046 的组件时失败,原因是出现以下错误: 80040154。[/color]rnrn软件是WinForm程序, C# + MySqlrn开发环境是XP sp1 32位的,Office 2007rn运行环境是Win7 64位,运行环境没有安装Office。rnrn软件打包的时候已经包含了rnMicrosoft.Office.Interop.Excel.dllrnMicrosoft.Vbe.Interop.dllrnInterop.Shell32.dllrnrn是否是因为运行环境没有安装Office?rnrn[color=#0000FF]BTW, 一个问题,.NET开发的程序,引用的外部DLL,如上面的Microsoft.Office.Interop.Excel.dllrn等等,在开发时,或者制作安装包时是否可以改名? 这名字实在太长了。[/color]
c# 中输出excel
我想在客户端输出excle怎么做,我会使用response在客户端输出csv文件,但是excle那样输出 的话,数据不能顺序写到对应的cell里。请大家告诉我一下。
求助!源代码执行没问题,编译后执行exe报错
[img=https://img-bbs.csdn.net/upload/201701/15/1484477559_124878.png][/img]
pb调用c# dll 报错,不能创建对象,本机开发环境没问题,别的机器上报错
用c#写了个dll 供pb调用,本机pb9 运行编译都没问题。pb生成可执行程序。 rnrncopy到另一台电脑上 用regasm 注册dll 成功,运行exe 都正常,也能正常调用这个dll。rnrn但是这台电脑上用pb9 打开源码 run的时候 就报错了 错误类型-3 不能创建对象。rnrnrnrn请教下有碰到类似情况的没?exe都能执行成功为什么在pb9开发环境下run不行呢?
WPF4应用程序,本机运行没问题,拷贝到其他机器就无法启动
各位大侠好。rn 小弟用WPF4写了一个小工具,在自己的开发机器上编译调试测试都没问题。把编译好的exe文件以及引用到了的dll全部拷贝到另一个机器上的时候,程序无法启动了。目标机器上是装好了Framework4.0的。所有相关的dll以及文件和exe文件一起都拷贝了的。下面是详细的错误信息。rnrnApplication: CMT.exernFramework Version: v4.0.30319rnDescription: The process was terminated due to an unhandled exception.rnException Info: System.Windows.Markup.XamlParseExceptionrnStack:rn at System.Windows.Markup.XamlReader.RewrapException(System.Exception, System.Xaml.IXamlLineInfo, System.Uri)rn at System.Windows.Markup.WpfXamlLoader.Load(System.Xaml.XamlReader, System.Xaml.IXamlObjectWriterFactory, Boolean, System.Object, System.Xaml.XamlObjectWriterSettings, System.Uri)rn at System.Windows.Markup.WpfXamlLoader.LoadBaml(System.Xaml.XamlReader, Boolean, System.Object, System.Xaml.Permissions.XamlAccessLevel, System.Uri)rn at System.Windows.Markup.XamlReader.LoadBaml(System.IO.Stream, System.Windows.Markup.ParserContext, System.Object, Boolean)rn at System.Windows.Application.LoadBamlStreamWithSyncInfo(System.IO.Stream, System.Windows.Markup.ParserContext)rn at System.Windows.Application.LoadComponent(System.Uri, Boolean)rn at System.Windows.Application.DoStartup()rn at System.Windows.Application.<.ctor>b__1(System.Object)rn at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)rn at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)rn at System.Windows.Threading.DispatcherOperation.InvokeImpl()rn at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)rn at System.Threading.ExecutionContext.runTryCode(System.Object)rn at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)rn at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)rn at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)rn at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)rn at System.Windows.Threading.DispatcherOperation.Invoke()rn at System.Windows.Threading.Dispatcher.ProcessQueue()rn at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)rn at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)rn at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)rn at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)rn at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)rn at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)rn at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)rn at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)rn at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)rn at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)rn at System.Windows.Threading.Dispatcher.Run()rn at System.Windows.Application.RunDispatcher(System.Object)rn at System.Windows.Application.RunInternal(System.Windows.Window)rn at System.Windows.Application.Run(System.Windows.Window)rn at CMT.App.Main()rn 第一次开发WPF4应用程序,以前从来没遇到过这个问题。rn 说明下,开发机器是win7 enterprise x64 english。目标机器的操作系统和开发机器是一样的,也是64位。IDE没用VS,用的是SharpDevelop(公司不让用盗版),编译的程序是32位的。rn
C# 执行EXCEL 宏
实现C#如何将宏写入EXCEL ,并且执行。将执行结果保存。
打开excel文件报错!!!
Excel.Application app=new Excel.ApplicationClass();rn if (app == null) rn rn statusBar1.Text = "ERROR: EXCEL couldn't be started!";rn return ;rn rn app.Visible = true; rn app.UserControl = true;rn Excel.WorkbookClass workbook =(Excel.WorkbookClass) app.Workbooks.Add("c:\\t1.xls");rn Excel.WorksheetClass worksheet=(Excel.WorksheetClass)workbook.Sheets.get_Item(0)///这里错误,该怎么改???rn if(worksheet==null)rn rn statusBar1.Text = "ERROR: worksheet == null";rn return;rn rn Excel.Range range1=worksheet.get_Range("A1","A5");
上传excel文件报错
上传excel文件,读取excel里的数据,调用存储过程插入到数据库里,然后报了读取超时错误,求教怎么解决rn错误如下:rn2013-07-19 11:09:50,661 [http-20750-2] ERROR org.apache.struts2.dispatcher.multipart.MultiPartRequest - Unable to parse requestrnorg.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Read timed outrn at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)rn at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parse(JakartaMultiPartRequest.java:92)rn at org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper.(MultiPartRequestWrapper.java:75)rn at org.apache.struts2.dispatcher.Dispatcher.wrapRequest(Dispatcher.java:663)rn at org.apache.struts2.dispatcher.FilterDispatcher.prepareDispatcherAndWrapRequest(FilterDispatcher.java:373)rn at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:438)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:97)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at cn.com.jd.task.common.filter.LoginFilter.doFilter(LoginFilter.java:87)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)rn at java.lang.Thread.run(Unknown Source)rnCaused by: java.net.SocketTimeoutException: Read timed outrn at java.net.SocketInputStream.socketRead0(Native Method)rn at java.net.SocketInputStream.read(Unknown Source)rn at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:716)rn at org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:746)rn at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:116)rn at org.apache.coyote.http11.InternalInputBuffer.doRead(InternalInputBuffer.java:675)rn at org.apache.coyote.Request.doRead(Request.java:419)rn at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:293)rn at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:405)rn at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:308)rn at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:193)rn at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:977)rn at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:887)rn at java.io.InputStream.read(Unknown Source)rn at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94)rn at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)rn at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)rn ... 31 more
C# 执行Excel宏
C# 调用 Excel 开发的VBA宏进行Excel操作 Excel宏文件 线程
c# 控制 excel
使用c#控制excel,已编成类,可直接调用,内有源码
c# Excel表单控制
可对Excel进行一些简单的操作!具体情况,自行了解。。。
C#控制Excel
做个系统,将GV的数据导到Excel中,但是我现在想设置每个单元格的字休大小,rnmyExcel.Cells.Font.Size = 10;rnmyExcel.Cells.Font.Bold = false;rnmyExcel.Cells.ColumnWidth = 15;rn这些都是对全表进行设定。rn问如何修改某个单元格的属性?
C# 控制excel图片大小
现在有张Excel,A1单元格里填充着由控件导出的图片,但是图片很大 现在我想缩小图片的大小rnrnrn望先人指点
如何在C#中执行JS文件,输出执行结果
我有2个文件rnrnA:一个JS文件 (promoto.js)rnB:一个JSON文件 (json.txt)rnrn我需要在winform中,点击按钮以后,把文件B中的变量代入到文件A中,执行A这个js脚本,输出执行结果。rnrnrnrn说明:rnrnA:js比较复杂有600多行,基本全部是if判断语句,主要是对JSON中的变量进行判断,然后根据JSON中变量不同的值,执行不同的JS文件块。rnrnB:Json文件变量较多,几十个。
poi导入下载的excel报错,导入自己创建的excel没问题?
Excel文件的后缀都是 .xls。rnrn报错信息如下:rnStruts Problem ReportrnrnStruts has detected an unhandled exception:rnrnMessages: rnPackage should contain a content type part [M1.13]rnorg.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]rnFile: org/apache/poi/openxml4j/opc/ZipPackage.javarnLine number: 147rnStacktracesrnrnorg.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]rn org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)rn org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:190)rn com.dfbyoa.commons.ImportExcel.getData(ImportExcel.java:122)rn com.xcd.manage.reconciliation.traveImport.action.BookImportAction.execute(BookImportAction.java:58)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn java.lang.reflect.Method.invoke(Unknown Source)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:314)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)rn org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)rn org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn com.dfbyoa.commons.filters.SessionFilter.doFilter(SessionFilter.java:56)rn org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)rn org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)rn org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)rn org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)rn org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)rn org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)rn org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)rn java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)rn java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)rn org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn java.lang.Thread.run(Unknown Source)rn rnYou are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:rnrn struts.devMode=falsernin your WEB-INF/classes/struts.properties file.
上传文本文件没问题,图片文件报错java.lang.IndexOutOfBoundsException
请大虾帮忙看看问题在哪?rn1、从request中读出字节: rn ServletInputStream stm=request.getInputStream();rn int len=request.getContentLength(),rn n=0;rn byte[] b=new byte[len];rn while(n
为什么API函数GetTempPathA写在按钮里没问题,但是移到一个函数里就报错(一个全局函数),并且有的电脑没问题,有的电脑就报错
Bad runtime function reference at line ......rnrn--------------------------rn这是我的声明语句:rnFUNCTION Long GetTempPathA(long nBufferLength, ref string lpBuffe) LIBRARY 'Kernel32.dll' rn
相关热词 c# 标准差 计算 c#siki第五季 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池