如何在.sln文件中使用.cs [英] how to use .cs in .sln file

查看:140
本文介绍了如何在.sln文件中使用.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用此代码



 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用 System.Linq;
使用 System.Text;
使用 System.Threading.Tasks;
使用 System.Windows.Forms;
使用 System.Diagnostics;


命名空间 ROD_PISTON1
{
public partial class Form1:Form
{
private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
private static Microsoft.Office.Interop.Excel.Application oXL;
private static Microsoft.Office.Interop.Excel.Worksheet mWSheet2;
public Form1()
{
InitializeComponent();
}

private void label2_Click( object sender,EventArgs e)
{

}

private void button1_Click( object sender,EventArgs e)
{
string path = @ C:\ Users \Dhaval \\ \\Desktop\BOOK1.xlsx;

oXL = new Microsoft.Office.Interop.Excel.Application();

oXL.Visible = false ;

oXL.DisplayAlerts = false ;

mWorkBook = oXL.Workbooks.Open(路径, 0 false 5 false ,Microsoft.Office.Interop。 Excel.XlPlatform.xlWindows, true false 0 true false false );

// 获取工作簿中的所有工作表

mWorkSheets = mWorkBook.Worksheets;

// 获取allready exists表

mWSheet1 =(Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item( INPUT) ;

// Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
// mWSheet1.Cells [3,3] = comboBox1.Text;
// mWSheet1.Cells [4,3] = comboBox2.Text;
// mWSheet1.Cells [5,3] = textBox3.Text;
// mWSheet1.Cells [6,3] = textBox4.Text;
// mWSheet1.Cells [7,3] = textBox5.Text;
// mWSheet1.Cells [8,3] = textBox6.Text;
/ / mWSheet1。单元格[9,3] = textBox7.Text;
// mWSheet1.Cells [10 ,3] = textBox8.Text;
// mWSheet1.Cells [11,3] = textBox9.Text;
// mWSheet1.Cells [12,3] = textBox10。文字;
// mWSheet1.Cells [13,3] = comboBox3.Text;
// (textBox+ i.ToString())。文字;

mWSheet2 =(Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item( OUTPUT);

Microsoft.Office.Interop.Excel.Range range = mWSheet2.UsedRange;

double i =(mWSheet2.Cells [ 3 3 ]值2)。
textBox12.Text = i.ToString();

double j =(mWSheet2.Cells [ 4 3 ]值2)。
textBox13.Text = j.ToString();

double k =(mWSheet2.Cells [ 5 3 ]值2)。
textBox14.Text = k.ToString();
mWorkBook.Save();
mWorkBook.Close();
流程p = new Process();
p.StartInfo.FileName = C:\\Users \\Dhaval \\\ \\Desktop\\ug\\rod.prt;
p.Start();

}
}
}





现在我需要添加以下代码





使用系统;

使用NXOpen;



内部静态类tmp

{

public static void Main()

{

Session s = Session.GetSession;

Part wp = s.Parts.Work;



foreach(表达式在wp.Expressions中展示)

{

if(exp.Equation.Contains(ug_excel_read))

{

var valeur = exp.Value ;





echo(表达式:+ exp.Name +已从外部Spreedsheet中取消引用,现在等于 + valeur);

}

}



}

public static void echo(字符串消息)

{

ListingWindow lw = Session.GetSession.ListingWindow;

lw.Open();

lw.WriteLine(消息);

}

public static int GetUnloadOption(string dummy)

{

返回NXOpen.Session.LibraryUnloadOption.Immediately;

}

}



请给我建议如何添加此代码





解决方案

你不能。

它们根本不兼容:你拥有的代码目前是WinForms,你要添加的代码是基于web的。



WinForms应用程序没有Session,你的加载代码似乎使用它

i have to use this code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;


namespace ROD_PISTON1
{
    public partial class Form1 : Form
    {
        private static Microsoft.Office.Interop.Excel.Workbook mWorkBook;
        private static Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
        private static Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
        private static Microsoft.Office.Interop.Excel.Application oXL;
        private static Microsoft.Office.Interop.Excel.Worksheet mWSheet2;
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path = @"C:\Users\Dhaval\Desktop\BOOK1.xlsx";

            oXL = new Microsoft.Office.Interop.Excel.Application();

            oXL.Visible = false;

            oXL.DisplayAlerts = false;

            mWorkBook = oXL.Workbooks.Open(path, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

            //Get all the sheets in the workbook

            mWorkSheets = mWorkBook.Worksheets;

            //Get the allready exists sheet

            mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("INPUT");

            // Microsoft.Office.Interop.Excel.Range range = mWSheet1.UsedRange;
            //mWSheet1.Cells[3, 3] = comboBox1.Text;
            //mWSheet1.Cells[4, 3] = comboBox2.Text;
            //mWSheet1.Cells[5, 3] = textBox3.Text;
            //mWSheet1.Cells[6, 3] = textBox4.Text;
            //mWSheet1.Cells[7, 3] = textBox5.Text;
            //mWSheet1.Cells[8, 3] = textBox6.Text;
            //mWSheet1.Cells[9, 3] = textBox7.Text;
            //mWSheet1.Cells[10, 3] = textBox8.Text;
            //mWSheet1.Cells[11, 3] = textBox9.Text;
            //mWSheet1.Cells[12, 3] = textBox10.Text;
            //mWSheet1.Cells[13, 3] = comboBox3.Text;
            //("textBox"+i.ToString()).Text;

            mWSheet2 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item("OUTPUT");

            Microsoft.Office.Interop.Excel.Range range = mWSheet2.UsedRange;

            double i = (mWSheet2.Cells[3, 3].Value2);
            textBox12.Text = i.ToString();

            double j = (mWSheet2.Cells[4, 3].Value2);
            textBox13.Text = j.ToString();

            double k = (mWSheet2.Cells[5, 3].Value2);
            textBox14.Text = k.ToString();
            mWorkBook.Save();
            mWorkBook.Close();
            Process p = new Process();
            p.StartInfo.FileName = "C:\\Users\\Dhaval\\Desktop\\ug\\rod.prt";
            p.Start();

        }
    }
}



now i have required to add below code


using System;
using NXOpen;

internal static class tmp
{
public static void Main()
{
Session s = Session.GetSession;
Part wp = s.Parts.Work;

foreach (Expression exp in wp.Expressions)
{
if (exp.Equation.Contains("ug_excel_read"))
{
var valeur = exp.Value;


echo("Expression: " + exp.Name + " has been unreferenced from external Spreedsheet, and is now equal to " + valeur);
}
}

}
public static void echo(string message)
{
ListingWindow lw = Session.GetSession.ListingWindow;
lw.Open();
lw.WriteLine(message);
}
public static int GetUnloadOption(string dummy)
{
return NXOpen.Session.LibraryUnloadOption.Immediately;
}
}

please give me suggestion how to add this code


解决方案

You can't.
They aren't compatible at all: the code you have at the moment is WinForms, the code you want to add is web based.

WinForms applications do not have a Session, and your add-in code appears to use it.


这篇关于如何在.sln文件中使用.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆