我们是否可以用c#开发一个.exe文件,以便宏在新机器中设置excel文件,该机器以前不包含任何宏
我需要开发一个.exe文件,每当我们点击它时,它应该将Personal.XLSB和Excel定制从一个文件夹复制到pertical machine的XLSTART文件夹(我已经完成了)。并选中developer选项卡的复选框,并通过c#代码导入Excel定制。可能吗?请帮忙我们是否可以用c#开发一个.exe文件,以便宏在新机器中设置excel文件,该机器以前不包含任何宏,c#,excel,vba,windows,C#,Excel,Vba,Windows,我需要开发一个.exe文件,每当我们点击它时,它应该将Personal.XLSB和Excel定制从一个文件夹复制到pertical machine的XLSTART文件夹(我已经完成了)。并选中developer选项卡的复选框,并通过c#代码导入Excel定制。可能吗?请帮忙 完成文件从一个地方复制到另一个地方。现在我要做的是导入Excel自定义文件并选中Excel选项中“开发人员”选项卡的复选框。这可以通过c#代码实现吗?好吧,只要您构建项目,就会创建一个EXE文件。所以…构建->批量构建并激活
完成文件从一个地方复制到另一个地方。现在我要做的是导入Excel自定义文件并选中Excel选项中“开发人员”选项卡的复选框。这可以通过c#代码实现吗?好吧,只要您构建项目,就会创建一个EXE文件。所以…构建->批量构建并激活发布配置中的“构建”复选框。单击build按钮时,将生成具有某些依赖项的exe。您可以在项目的调试文件夹中找到此文件
C:\Users\username\Documents\Visual Studio 2012\Projects\ProjectName\bin\Debug
这是代码
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("Excel is not properly installed!!");
return;
}
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "ID";
xlWorkSheet.Cells[1, 2] = "Name";
xlWorkSheet.Cells[2, 1] = "1";
xlWorkSheet.Cells[2, 2] = "One";
xlWorkSheet.Cells[3, 1] = "2";
xlWorkSheet.Cells[3, 2] = "Two";
xlWorkBook.SaveAs("d:\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
MessageBox.Show("Excel file created , you can find the file d:\\csharp-Excel.xls");
}
}
}
另外,请参见下面的链接
好吧,只要您构建项目,就会创建一个EXE文件。所以…构建->批量构建并激活发布配置中的“构建”复选框。单击build按钮时,将生成具有某些依赖项的exe。您可以在项目的调试文件夹中找到此文件
C:\Users\username\Documents\Visual Studio 2012\Projects\ProjectName\bin\Debug
这是代码
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("Excel is not properly installed!!");
return;
}
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Cells[1, 1] = "ID";
xlWorkSheet.Cells[1, 2] = "Name";
xlWorkSheet.Cells[2, 1] = "1";
xlWorkSheet.Cells[2, 2] = "One";
xlWorkSheet.Cells[3, 1] = "2";
xlWorkSheet.Cells[3, 2] = "Two";
xlWorkBook.SaveAs("d:\\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
Marshal.ReleaseComObject(xlWorkSheet);
Marshal.ReleaseComObject(xlWorkBook);
Marshal.ReleaseComObject(xlApp);
MessageBox.Show("Excel file created , you can find the file d:\\csharp-Excel.xls");
}
}
}
另外,请参见下面的链接