Ejemplo n.º 1
0
        internal static void ImportPromptList(string initialDirectory)
        {
            string fileName;

            // Set up the open file dialog and let the user select the file to open.
            if (openFileDialog == null)
            {
                openFileDialog             = new OpenFileDialog();
                openFileDialog.Title       = Common.GetResourceString(Strings.OpenPromptsTitleRes);
                openFileDialog.Filter      = Common.GetResourceString(Strings.OpenPromptsFilterRes);
                openFileDialog.FilterIndex = 1;
            }

            openFileDialog.InitialDirectory = initialDirectory;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // The user selected a valid file name and hit OK. Get the
                // file name from the dialog and open the file.
                fileName = openFileDialog.FileName;

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

                if (excelApp == null)
                {
                    Common.ErrorMessage("Couldn't start Excel - make sure it's installed");
                    return;
                }
                excelApp.Visible = false;

                Workbook wb = excelApp.Workbooks.Open(fileName, ReadOnly: true);
                if (wb.Worksheets.Count > 0)
                {
                    Worksheet ws = (Worksheet)wb.Worksheets[1];

                    string promptId, dupIds, wording, notes;

                    PromptRecordingList recordingList = new PromptRecordingList();

                    int row = 7;
                    do
                    {
                        promptId = ws.Cells[row, 2].Text;
                        dupIds   = ws.Cells[row, 3].Text;
                        wording  = ws.Cells[row, 4].Text;
                        notes    = ws.Cells[row, 5].Text;

                        if (notes.Length > 0)
                        {
                            wording = wording + " " + Strings.LabelStartBracket + notes + Strings.LabelEndBracket;
                        }

                        if (promptId != null && promptId.Length > 0 && wording != null)
                        {
                            recordingList.AddPromptRecording(promptId, wording);

                            if (dupIds != null && dupIds.Length > 0)
                            {
                                string[] otherIds = dupIds.Split(DuplicateIdDelimiter);

                                foreach (string dupId in otherIds)
                                {
                                    recordingList.AddPromptRecording(dupId, wording);
                                }
                            }
                        }
                        row++;
                    } while (promptId != null && promptId.Length > 0);

                    Common.ApplyPromptRecordingList(recordingList);
                }

                wb.Close();
                excelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
                excelApp = null;
            }
        }