Net Core教程

在C#代码中编写宏操作Excel

本文主要是介绍在C#代码中编写宏操作Excel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

Workbook oBook; Application oXlsApp; private void OpenExcelConnection()//创建workBook对象 { oXlsApp = new Application(); oXlsApp.Visible = false; // Excel表示有無 oXlsApp.DisplayAlerts = false; // Excelの確認ダイアログ表示有無 oBook = (oXlsApp.Workbooks.Open( excelFileName, // Filename Type.Missing, // UpdateLinks Type.Missing, // ReadOnly Type.Missing, // Format Type.Missing, // Password Type.Missing, // WriteResPassword Type.Missing, // IgnoreReadOnlyRecommended Type.Missing, // Origin Type.Missing, // Delimiter Type.Missing, // Editable Type.Missing, // Notify Type.Missing, // Converter Type.Missing, // AddToMru Type.Missing, // Local Type.Missing // CorruptLoad )); oSheet = (Worksheet)oBook.ActiveSheet; } private void CreateMacro()//创建宏 { try { VBIDE.VBComponent oModule; oModule = oBook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule); string sCode = @" Sub StyleChange() Application.DisplayAlerts = False Dim i, j, k, str, Sheet,

这篇关于在C#代码中编写宏操作Excel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!