Tag: c# 4.0

如何在C#窗口应用程序窗体中实际不知道目录中的完整path文件而自动find文件

我需要帮助我的C#应用​​程序,我的应用程序是基本完成只需要一个小调整,应该完成。 我的程序有许多function。 但我需要帮助的是以下几点: 我的程序会先让用户创build一个excel文件,在那里我有三个button,第一个button是打开的,会打开用户创build的创build文件,用户将文件保存在任何位置,但是当打开的button需要find该文件到用户保存文件的位置。 现在button将工作,如果我手动把文件的具体位置的位置。 但我的应用程序将使用它很多用户。 每个用户将自己的文件保存在任何目录位置。 我也有一个button,将数据保存到Excel文件,也closures它,但只要打开的文件工作正常工作。 这部分代码将创build并保存到用户所需的位置。 那么打开buttonfunction就需要自动find刚刚从计算机目录下创build的新文件。 正如我之前所说,如果我把特定的位置打开button的作品,但我不想放在文件的具体位置,因为用户将select的Excel文件的位置。 private void tlpMenuItem_SaveAs_Click(object sender, EventArgs e) { string sd; svFileDialog_SaveButton.ShowDialog(); //saveFileDialog1.InitialDirectory = "c:"; svFileDialog_SaveButton.Filter = "Excel File|*.xlsx|All Files|*.*"; Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application(); ExcelApp.Application.Workbooks.Add(Type.Missing); ExcelApp.Columns.ColumnWidth = 20; sd = svFileDialog_SaveButton.FileName; ExcelApp.ActiveWorkbook.SaveCopyAs(sd + ".xlsx"); ExcelApp.ActiveWorkbook.Saved = true; ExcelApp.Quit(); MessageBox.Show("Excel file created"); } private void OpenFile() […]

将工作簿保存到stream而不是文件

是否有可能(以及如何)将Microsoft Excel工作簿保存到stream而不是文件? 我现在拥有的是: using System.Runtime.InteropServices; // Microsoft Excel 14.0 Object Library ……. workbook.SaveAs(Filename: fileName, FileFormat: XlFileFormat.xlWorkbookNormal); 但是,这两个文档作为intellisense给我不知道如何把它放在一个stream并写入一个BinaryWriter例如通过浏览器输出它。

使用C#在Excel中对多个列进行sorting

我需要使用C#在Excel中的多个列进行sorting。 我正在使用Microsoft.Office.Interop.Excel做这个。 但Range.Sort允许我sorting只有三列。 我想分三个以上的列? 有没有办法,我可以使用Excel.Range.Sort方法来sorting超过三列?

无法获得全名,当我尝试下载一个Excel

当我尝试下载一个文件的全名,它没有得到下载。 但在一个参数中发送参数作为文件名。 文件path是自动生成的。 正在下载文件名是:Update_4_Product(显示在屏幕截图中) 实际的文件名是:Update_4_Product Details.xlsx 这是我的代码 private void DownloadUploadDataTemplate(string fileName) { string Outgoingfile = fileName + ".xlsx"; string targetDirectory = Path.GetDirectoryName(XTP.Caching.AppSettingCache.GalleryFilePath) + @"\" + this.TenantCode + "\\Files" + @"\" + Outgoingfile; System.IO.FileInfo file = new System.IO.FileInfo(targetDirectory); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/vnd.ms-excel"; Response.WriteFile(file.FullName); HttpContext.Current.ApplicationInstance.CompleteRequest(); } else […]

将XElement导出到Excel

假设我有以下列出的Log对象,并希望将列表导出到Excel。 我想将List<Log>转换为Excel。 我可以手动创build数据集,但有一个更聪明的方法? String xml1 = "<CustomerPricing><Id>673</Id><Customer>3</Customer><Code>XV1</Code><PricingType>20</PricingType><Discount>33</Discount><Company>10</Company></CustomerPricing>"; String xml2 = "<CustomerPricing><Id>674</Id><Customer>3</Customer><Code>XV1</Code><PricingType>30</PricingType><Discount>35</Discount><Company>10</Company></CustomerPricing>"; Log log1 = new Log { ModifiedBy = "user", DateModified = DateTime.Now, ChangedData = XElement.Parse(xml1) }; Log log2 = new Log { ModifiedBy = "user", DateModified = DateTime.Now, ChangedData = XElement.Parse(xml2) }; List<Log> logs = new List<Log> { log1, log2 }; 类: public class […]

从客户端Web应用程序中提取excel内容

我有一个Web应用程序(ASP.Net),需要上传一个文件 我一直在寻找一个框架,从客户端提取Excel中的数据,并提交内容(JSON,CSV)格式到服务器端,以减lessstream量。 我已经在javascript中查看ActiveXObject,但它只能在Internet Explorer中工作。 我有一个select使用Silverlight或动作来parsing。 题: 银光真的死了吗? 我不能长期使用它吗? 这可能使用动作脚本? 有没有任何JavaScript框架来做这种parsing? 提前致谢

在c#程序中预览Excel并dynamic编辑它

我有一个问题,即使看起来似乎也看不懂类似的post。 我有一个Excel文件,我用它作为模板,我在C#程序中读取它,并用我想要的数据填充它,然后用其他名称保存。 但是我想在程序中有一种types的窗口,可以在创build之前使用插入的数据预览模板,就像这样,如果用户只想查看数据,用户就不需要创build该文件。 有没有办法做到这一点? 最近的一个。 PS:我正在使用Visual Studio 2010 Professional和Microsoft Excel 2010。 谢谢

我们如何才能将Excel单元格的数据types更改为CellValues.String从C#

我们如何改变c#中每个excel列的DataType = CellValues.String。 for (int index = 0; index < NoOfRecords; index++) { for (int j = 0; j < colCount; j++) { mWSheet1.Cells[(rowCount) + index, j + 1] =Convert.ToString(ResultsData.Rows[index][j].ToString()); } }

如何使用openxml读取excel文件的单元格数据

我正在使用DocumentFormat.openxml nuget pkg读取.xlsx文件。 我试图读取date单元格[G2]和数据从[b5]到[m5] static void Main(string[] args) { string sFileTypeError = string.Empty; string myFilePath = @"C:\Landing\file.xlsx"; //string ext = Path.GetExtension(myFilePath); var fileName = Path.GetFileName(myFilePath); var fileExtension = Path.GetExtension(fileName); if ((fileExtension != ".xlsx") && (fileExtension != ".xls")) sFileTypeError = "Invalid file. \n\nPlease browse a correct Excel file to upload."; else { using (SpreadsheetDocument doc = […]

不知道为什么我得到Excel文件的System.Data.OleDb.OleDbException

OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; // Show the dialog and get result. DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) // Test result. { labelFilePath.Text = openFileDialog1.FileName; string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + labelFilePath.Text.Trim() + ";Extended Properties=\"Excel 8.0;HDR=YES\""; using (var conn = […]