Tag: interop

捆绑Microsoft.Office.Interop.Excel.dll作为资源不起作用

我在写一个使用SQLite和Excel的C#程序。 自然,我需要System.Data.SQLite.dll和Microsoft.Office.Interop.Excel.dll。 我想我的程序是一个单一的exe文件,所以我想捆绑在程序集中的这些DLL。 这是我的.csproj文件: <Project DefaultTargets="Compile" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <appname>AppName</appname> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> </PropertyGroup> <ItemGroup> <CSFile Include="*.cs"/> </ItemGroup> <ItemGroup> <DLLResource Include="System.Data.SQLite.dll"/> <DLLResource Include="Microsoft.Office.Interop.Excel.dll"/> <DLLReference Include="System.Data.SQLite.dll"/> <DLLReference Include="Microsoft.Office.Interop.Excel.dll"/> </ItemGroup> <ItemGroup> <BundledResource Include="std_db_build.xml"/> <BundledResource Include="std_report_make.xml"/> </ItemGroup> <Target Name="Compile"> <CSC Sources="@(CSFile)" Resources="@(DLLResource);@(BundledResource)" References="@(DLLReference)" OutputAssembly="$(appname).exe"> </CSC> </Target> <Target Name="Run"> <Exec Command="start $(COMSPEC) /k &quot;$(PathTo)$(appname).exe &amp; pause>null &amp; exit&quot;" /> </Target> <Target Name="Clean"> […]

在Windows窗体中embeddedExcel 2010文档

我一直试图解决这个问题整天,希望这里有人已经想出了如何做到这一点 – 我试图在我的Windows窗体中显示一个Excel 2010工作表,并没有指望这是困难的。 所以…从我在网上看到的,最好的方法是通过一个WebBrowser控件 – 我的代码很容易: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strfilename = Application.StartupPath & "\SheetXX.xlsx" WebBrowser1.Navigate(strfilename, False) End Sub 但是它popup一个文件下载对话框。 起初,我的问题是,即使当我按下“打开”button,它打开Excel在一个单独的窗口。 我设法修复使用这个registry修复程序 ,但它仍然popup对话框,然后在我的最终用户会抱怨我的浏览器打开它。 其他的在线解决scheme提到了微软的dsoframer,但是这对我来说根本不起作用。 任何人都知道如何使这个工作? 简单而简单,我只想看到我的窗体中的Excel表单。 谢谢!!

如何使用Microsoft.Interop Excel从MS Excel访问OLE对象

我正在尝试访问一个OLE对象(embedded到Excel工作表中)的报表。 我正在尝试使用Microsoft.Interop.Excel API从C#控制台应用程序执行此操作。 我成功地能够遍历工作表中存在的OLE对象。 但是,当我尝试访问OLEObject实例的对象属性,我得到一个COMexception。 有没有人尝试过之前成功。 请帮助我的示例代码。 代码我尝试POC如下 static void Main(string[] args) { string fileName = string.Empty // some excel file path Application _excelApp = new Application(); _excelApp.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable; Workbook workBook = _excelApp.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); for (int i = 1; i <= […]

使用互操作将具有多个工作表的xls或xlsx文件转换为一个csv文件

我正在尝试使用c#和互操作库将具有多个工作表的xls或xlsx文件转换为一个CSV文件。 我只是获取CSV文件中的一张。 我知道我可以指定工作表保存为或更改活动工作表以保存该工作表,但我正在寻找一个解决scheme,将所有工作表附加到同一个CSV文件,将使用xls和xlsx文件。 我自动化这个,不关心什么是在Excel文件只是想拉出string值并将其附加到CSV文件。 这是我正在使用的代码: Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); app.Visible = false; app.DisplayAlerts = false; Workbook wkb = app.Workbooks.Open(fullFilePath); wkb.SaveAs(newFileName, XlFileFormat.xlCSVWindows); 这甚至有可能吗?

Powerpoint修改图表图例宽度

我正在使用VB.net在Powerpoint中创build图表并产生一个小问题:客户希望图例比原始devise更大。 Interop可以吗? 我基本上有这样的结构: Dim TargetChartas Microsoft.Office.Interop.PowerPoint.Chart TargetChart.HasLegend=true With TargetChart.Legend .Position = Microsoft.Office.Interop.PowerPoint.XlLegendPosition.xlLegendPositionTop .Format.TextFrame2.TextRange.Font.Bold = Microsoft.Office.Core.MsoTriState.msoCTrue .Format.Line.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue End Width 但我无法find一个宽度属性 – 像任何正常的形状posess。 你有什么想法如何做到这一点? 我添加了Excel的标签,因为图表基本上是Excel图表。 阿格:我需要更多的茶。 我刚刚意识到Office 2010有一个宽度属性,而2007年没有。 所以我只需要检查一下PPT的版本哦哦

AutoFit函数不在Excel中格式化单元格

Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Workbooks.Add(); Microsoft.Office.Interop.Excel._Worksheet workSheet = excel.ActiveSheet; try { workSheet.Cells[1, "A"] = "Number #"; workSheet.Cells[1, "B"] = "Firstname"; workSheet.Cells[1, "C"] = "Lastname"; workSheet.Cells[1, "D"] = "Email"; workSheet.Cells[1, "E"] = "Mobile"; // ———————————————— // Populate sheet with some real data from list // ———————————————— int row = 2; // start row (in row […]

从多个数据库表以编程方式创build数据透视表

我有一个自动化Excel的问题,我无法解决。 我想模仿“导入外部数据”function。 它已经完美地适用于平面表,但不适用于数据透视表,当我为导入select多个数据库表时。 手动的方式 我有一个Access数据库与2个表(帐户和交易),由外键(交易表中的“帐户”)链接。 我想要立即导入到数据透视表。 通常的方法是点击“数据” – >“外部数据”,然后在对话框中select两个表格,然后select“数据透视表”并点击“确定”。 现在数据透视表位于活动工作表中,右侧是提供导入表的层次结构中所有字段的字段列表。 这是我想模仿提到的数据库文件。 有没有人有一个想法这是如何工作的? 我试过了 我已经试图logging和修改一个macros,但没有成功,因为它logging了不完整和有缺陷的代码。 不完整,因为logging的代码没有创build数据模型,但这显然是必要的(?)。 由于代码无法运行,因此语法错误。 我可以从一个数据库表成功创build数据透视表,如下所示: Excel.PivotCaches pivotCaches = workbook.PivotCaches(); Excel.PivotCache pivotCache = pivotCaches.Create(Excel.XlPivotTableSourceType.xlExternal, Type.Missing, Type.Missing); pivotCache.Connection = conStr; pivotCache.MaintainConnection = true; pivotCache.CommandText = "Accounts"; pivotCache.CommandType = Excel.XlCmdType.xlCmdTable; Excel.PivotTables pivotTables = sheet.PivotTables(); Excel.PivotTable pivotTable = pivotTables.Add(pivotCache, sheet.get_Range("A3", "C20"), "Pivot", Type.Missing, Type.Missing); 但是,我试图获得多个数据库表的每一次尝试都失败了。 什么是去多个表的方式? 请记住,我不一定知道表名称和连接字段,再加上我不想失去表格之间的区别,它应该保留在数据透视表字段列表中,以便对字段进行分层select。 […]

C#铸造系统.__ comobject类types

我有一个Excel加载项,我目前正试图build立一个unit testing框架。 对于unit testing,我遵循这个指南: http : //blogs.msdn.com/b/varsha/archive/2010/08/17/writing-automated-test-cases-for-vsto-application.aspx 它似乎工作正常,直到我想从我的界面返回一个类对象。 指定类对象作为返回types在调用方法时抛出“返回参数具有无效types”exception。 将类的返回types更改为对象允许我调用方法并获取对象,但是现在我无法将其转换为类并按预期方式使用,因此在尝试时会得到此exception消息: > Unable to cast COM object of type 'System.__ComObject' to class type > 'XYCoordinates'. Instances of types that represent COM > components cannot be cast to types that do not represent COM > components; however they can be cast to interfaces as long as the […]

C#Interop执行后不closuresExcel进程

我有以下代码块: Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(this.pathToFile); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; 我将xlRange推入一个数组,使用: someArray = (System.Object[,])xlRange.Value2; 之后,我尝试清理: Marshal.ReleaseComObject(xlRange); Marshal.ReleaseComObject(xlWorksheet); xlWorkbook.Close(); Marshal.ReleaseComObject(xlWorkbook); xlApp.Quit(); Marshal.ReleaseComObject(xlApp); 但是,即使所有四个excel对象都与Marshal发布,该进程仍保持打开状态,并防止再次打开该文件。 有关如何正确清理Interop excel对象的任何想法?

仅在Excel Interop中获取一个列的UsedRange

使用Microsoft的Excel Interop我正在阅读电子表格。 我没有问题得到整个工作表的使用范围,但我想获得只用于一列的行数。 这是我的工作表的一个例子: 正如你所看到的,列A的使用范围只有3行,而列B是5行。 当我使用我目前的代码: int rows = sheet.UsedRange.Rows.Count; 总是返回“5”。 我如何指定我只想要一个单元格的使用范围?