Example #1
0
        public static void SexUpWorksheets()
        {
            Tables.Clear();
            MetaData.Clear();

            int index = 1;

            foreach (Excel.Worksheet sheet in Globals.Sexel.Application.Worksheets)
            {
                try
                {
                    if (sheet.Name.StartsWith(WorksheetName_MetaDataPrefix))
                    {
                        MetaData.BuildFrom(sheet);
                    }
                    else if (sheet.Name.StartsWith(WorksheetName_TablePrefix))
                    {
                        string suffix = sheet.Name.Substring(WorksheetName_TablePrefix.Length).Trim();
                        if (suffix.Length == 0)
                        {
                            throw new Exception("Missing name. Sheet name has format 'Table <name>' where <name> is an alphanumeric string optionally padded with spaces");
                        }

                        var table = new TableParser(suffix, sheet);
                        Tables.Add(table);
                    }
                    index++;
                }
                catch (Exception ex)
                {
                    Sexel.ShowMessage(string.Format("Error in worksheet #{0} '{1}':\n{2}", index, sheet.Name, ex.Message));
                }
            }
        }
Example #2
0
        private void format_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                Sexel.ValidateSexelFile();
            }
            catch (Exception ex)
            {
                Sexel.ShowMessage(ex.Message);
            }

            Sexel.SexUpWorksheets();

            this.exportSXY.Enabled = Tables.Items.Count > 0;
        }
Example #3
0
        public static void ExportToSXY(string filename)
        {
            if (Tables.Items.Count == 0)
            {
                Sexel.ShowMessage("There were no tables to export. Sex-up the worksheet and try again.");
            }

            try
            {
                var sexport = new Sexport(filename);
                sexport.AppendHeaders();

                sexport.AppendClass();

                System.IO.File.WriteAllText(filename, sexport.ToString(), Encoding.UTF8);
            }
            catch (Exception ex)
            {
                Sexel.ShowMessage(ex.Message);
            }
        }