Esempio n. 1
0
        /// <summary>
        /// This event is used when there are linked files, to load them on demand.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Work_LoadLinkedFile(object sender, LoadLinkedFileEventArgs e)
        {
            //IMPORTANT: DO NOT USE THIS METHOD IN PRODUCTION IF SECURITY IS IMPORTANT.
            //This method will access any file in your harddisk, as long as it is linked in the spreaadhseet, and
            //that could mean an IMPORTANT SECURITY RISK. You should limit the places where the app can search for
            //linked files. Look at the "Recalculating Linked Files" in the PDF API Guide for more information.

            string FilePath = Path.Combine(Path.GetDirectoryName(openFileDialog1.FileName), e.FileName);

            if (File.Exists(FilePath)) //If we find the path, just load the file.
            {
                e.Xls = new XlsFile();
                e.Xls.Open(FilePath);
                return;
            }

            //If we couldn't find the file, ask the user for its location.
            linkedFileDialog.FileName = FilePath;
            if (linkedFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;                                                    //if user cancels, e.Xls will be null, so no file will be used and an #errna error will show in the formulas.
            }
            e.Xls = new XlsFile();
            e.Xls.Open(linkedFileDialog.FileName);
        }
        /// <summary>
        /// This event is used when there are linked files, to load them on demand.
        /// </summary>
        private void Workspace_LoadLinkedFile(object sender, LoadLinkedFileEventArgs e)
        {
            //In order to reduce the risk of opening any file, in this demo we are going to only open files in the same folder we are working on.
            XlsFile xls          = new XlsFile();
            string  TemplatePath = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), ".."), "..");

            xls.Open(Path.Combine(TemplatePath, Path.GetFileName(e.FileName)));

            e.Xls = xls;

            //A normal event should end here. Since we need to change the values of the file we loaded in demand, we will do that here.
            xls.SetCellValue(4, 2, GetValue(ChartA1.Text));
            xls.SetCellValue(5, 2, GetValue(ChartA2.Text));
            xls.SetCellValue(6, 2, GetValue(ChartA3.Text));
            xls.SetCellValue(4, 3, GetValue(ChartB1.Text));
            xls.SetCellValue(5, 3, GetValue(ChartB2.Text));
            xls.SetCellValue(6, 3, GetValue(ChartB3.Text));
        }