Hi,
Here is a sample of automating Excel. It enters some values in cells, runs a macro called "test", then fetches a cell value.
For a sample of automating Mathcad Prime look at "Re: Mathcad Prime Interface / API" in section of Top Kudoed Posts.
Do you want someone to do the automation for you, if you can share the sheets?
using System;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelMathCad
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static Excel.Application MyApp = null;
private static Excel.Workbook MyBook = null;
private static Excel.Worksheet MySheet = null;
private int lastRow;
private void button1_Click(object sender, EventArgs e)
{
MyApp = new Excel.Application();
MyApp.Visible = true;
MyBook = MyApp.Workbooks.Open(@"D:\\Prime\\Questions\\Book1.xlsm");
MySheet = (Excel.Worksheet)MyBook.Sheets[1]; // Explicit cast is not required here
lastRow = MySheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell).Row;
lastRow += 1;
MySheet.Cells[lastRow, 1] = "Six";
MySheet.Cells[lastRow, 2] = 14;
MySheet.Cells[lastRow, 3] = "Test";
MySheet.Cells[lastRow, 4] = 30.9;
MyApp.Run("Test");
double val = MySheet.Cells[1, 4].Value;
MyBook.Save();
MyBook.Close();
MyApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(MySheet);
MySheet = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(MyBook);
MyBook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(MyApp);
MyApp = null;
}
}
}