简体   繁体   English

Microsoft.Office.Interop.Excel - 如何将 Excel(仅可见单元格)保存到 Z1423DE713A2E4D3B38D7 中的 CSV

[英]Microsoft.Office.Interop.Excel - How to save Excel (Visible cells only) to CSV in vb.net

Currently I can save Excel to CSV as code below.目前我可以将 Excel 保存到 CSV 如下代码。 However, it's save all data which is including invisible cells.但是,它保存了包括不可见单元格的所有数据。

Dim excelApplication As Microsoft.Office.Interop.Excel.Application
Dim workbook As Microsoft.Office.Interop.Excel.Workbook
excelApplication = New Microsoft.Office.Interop.Excel.Application
excelApplication.Visible = False
excelApplication.DisplayAlerts = False
workbook = excelApplication.Workbooks.Open(in_InputFilePath)
workbook.SaveAs(in_OutputFilePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV)
workbook.Close()
excelApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication)
Dim excelApplication As Microsoft.Office.Interop.Excel.Application
Dim workbook1 As Microsoft.Office.Interop.Excel.Workbook
Dim workbook1worksheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim workbook1worksheet1range1 As Microsoft.Office.Interop.Excel.Range
Dim workbook2 As Microsoft.Office.Interop.Excel.Workbook
Dim workbook2worksheet1 As Microsoft.Office.Interop.Excel.Worksheet
Dim workbook2worksheet1range1 As Microsoft.Office.Interop.Excel.Range
excelApplication = New Microsoft.Office.Interop.Excel.Application
excelApplication.Visible = False
excelApplication.DisplayAlerts = False
workbook1 = excelApplication.Workbooks.Open(in_InputFilePath)
workbook1worksheet1 = CType(workbook1.Sheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
workbook1worksheet1.Select(Type.Missing)
workbook1worksheet1range1 = workbook1worksheet1.UsedRange.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeVisible, Type.Missing)
workbook1worksheet1range1.Copy
workbook2 = excelApplication.Workbooks.Add()
workbook2worksheet1 = CType(workbook2.Sheets("Sheet1"), Microsoft.Office.Interop.Excel.Worksheet)
workbook2worksheet1range1 = workbook2worksheet1.Range("A1")
workbook2worksheet1range1.PasteSpecial()
workbook2.SaveAs(in_OutputFilePath, Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV)
workbook2.Save()
workbook2.Close()
workbook1.Close()
excelApplication.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook2worksheet1range1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook2worksheet1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook2)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1worksheet1range1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1worksheet1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook1)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft.Office.Interop.Excel VB.NET如何禁用工作表中的选择锁定值 - Microsoft.Office.Interop.Excel VB.NET How to disable select locked values in a worksheet 尝试在 Linux 中使用 Microsoft.Office.Interop.Excel 和 VB.NET - Try to use Microsoft.Office.Interop.Excel with VB.NET in Linux 如何使用Microsoft.Office.Interop.Excel在SSIS 2013中找到VB.Net的正确语法? - How do I find the right syntax for VB.Net in SSIS 2013 using Microsoft.Office.Interop.Excel? 为什么即使导入Microsoft.Office.Interop.Excel(VB.NET),也无法在所有Excel对象上获得“未定义”? - Why do I get “not defined” on all the Excel objects even after importing Microsoft.Office.Interop.Excel (VB.NET)? 以任何方式调用VB.NET中的Excel函数作为Microsoft.Office.Interop.Excel会在服务器中引发未注册的类(REGB_E_CLASSNOTREG)? - Any way to call Excel functions in VB.NET as Microsoft.Office.Interop.Excel throws Class not registered (REGB_E_CLASSNOTREG) in Server? 如何以编程方式检查Microsoft.Office.Interop.Excel是否可用于VB? - How can I check programmatically if Microsoft.Office.Interop.Excel is available for use with VB? 如何在控制台应用程序上导入Microsoft.Office.Interop.Excel? - How to import Microsoft.Office.Interop.Excel on a console application? 如何在vb.net中转换Microsoft.Office.Interop.Excel.Application.Run结果? - How to cast Microsoft.Office.Interop.Excel.Application.Run result in vb.net? 导入和导出Excel数据到vb.net时出错,“未定义Microsoft.Office.Interop.Excel.Application” - Error importing and exporting excel data to vb.net, “Microsoft.Office.Interop.Excel.Application is not defined” Excel到DataTable? 不使用Microsoft.Office.Interop.Excel - Excel to DataTable? Without using Microsoft.Office.Interop.Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM