Beispiel #1
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            var settings = new CustomXML.UserSettings(_excel.ActiveWorkbook);

            settings.prepend = "";
            txtPrepCode.Text = settings.prepend;
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var settings = new CustomXML.UserSettings(_excel.ActiveWorkbook);

            settings.path    = txtPyPath.Text;
            settings.args    = txtExeString.Text;
            settings.prepend = txtPrepCode.Text;
            this.Close();
        }
Beispiel #3
0
        public void btnSettings_Click()
        {
            var settings = new CustomXML.UserSettings(_excel.ActiveWorkbook);

            SettingsForm sf = new SettingsForm(_excel);

            sf.txtPyPath.Text    = settings.path;
            sf.txtExeString.Text = settings.args;
            sf.txtPrepCode.Text  = settings.prepend;

            sf.ShowDialog();
        }
Beispiel #4
0
        public static void Start(string sheetName = "")
        {
            CTPManager.Save();
            var _excel = new Application(null, ExcelDna.Integration.ExcelDnaUtil.Application);

            var    activeSheet = sheetName == "" ? (Worksheet)_excel.ActiveSheet : (Worksheet)_excel.ActiveWorkbook.Worksheets[sheetName];
            string sourceCode  = PythonSourceManager.GetSourceCode(activeSheet.Parent as Workbook, activeSheet.Name);

            //remove non-printable characters
            sourceCode = Regex.Replace(sourceCode, @"[^ -~\n\t]+", " ");

            if (sourceCode.Length > 0)
            {
                var settings           = new CustomXML.UserSettings(_excel.ActiveWorkbook);
                var workbookPath       = "\"" + _excel.ActiveWorkbook.Path.Replace("\\", "\\\\") + "\"";
                var expandedSourceCode = "workbookPath=" + workbookPath
                                         + "\nimport os, pandas\nif(len(workbookPath)>1): os.chdir(workbookPath)\nresult = pandas.DataFrame()\n"
                                         + settings.prepend + "\n"
                                         + sourceCode
                                         + "\nif(result.shape[0] != 0): table[this] = result";

                var tempCol  = new TempFileCollection(Path.GetTempPath(), false);
                var filename = tempCol.AddExtension("py");
                File.WriteAllText(filename, expandedSourceCode);

                //Run Python code
                _excel.StatusBar = $"Running Python for '{activeSheet.Name}' In Background ...";
                Run(settings.path, Path.Combine(settings.args, filename), sourceCode, activeSheet);
                _excel.StatusBar = "";
                //
            }
            else
            {
                MessageBox.Show("There is no table refresh code associated with this worksheet.", "Refresh Table Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }