Beispiel #1
0
        public short NewWorksheet(string name = "")
        {
            try {
                System.Resources.ResourceManager resourceManager =
                    new System.Resources.ResourceManager("fastxcel.Resource", GetType().Assembly);


                var assembly = System.Reflection.Assembly.GetExecutingAssembly();

                short  new_ws_number = (short)(Worksheets.Count + 1);
                string res_id        = "Re";

                Worksheet new_wrk = new Worksheet(shared_strings);

                if (name == String.Empty)
                {
                    name = "Worksheet" + Worksheets.Count.ToString();
                }

                // First of all - create new xml file
                int num = 1;
                while (File.Exists(temp_path + "\\xl\\worksheets\\sheet" + num.ToString() + ".xml"))
                {
                    ++num;
                }
                string new_file_path = temp_path + "\\xl\\worksheets\\sheet" + num.ToString() + ".xml";
                string resource_path = assembly.GetName().Name + ".Resources.sheet_xml";

                BinaryReader br          = new BinaryReader(assembly.GetManifestResourceStream(resource_path));
                long         file_length = assembly.GetManifestResourceStream(resource_path).Length;
                byte[]       inners      = new byte[file_length];
                inners = br.ReadBytes((int)file_length);

                br.Close();

                FileStream   fs = File.Create(new_file_path);
                BinaryWriter bw = new BinaryWriter(fs);

                bw.Write(inners);
                bw.Close();


                // Register relationship
                int res_id_num = xml_wb_rels.XmlElements.Count;

                AddNewRelationship(num, "rId" + res_id_num.ToString(), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet");

                // Add into workbook.xml
                AddSheetInWorkbook("rId" + res_id_num.ToString(), name, new_ws_number);

                // Finally
                new_wrk.Load(new_file_path, shared_strings);

                Worksheets.Add(new_wrk);

                return(new_ws_number);
            } catch (Exception ex) {
                throw new FastXcelException("Can't create new worksheet" + ex.Message, ex);
            }
        }
Beispiel #2
0
        private void ProcessWorksheets()
        {
            try {
                Worksheets.Clear();
                string[] xl_sheet_files = Directory.GetFiles(temp_path + "\\xl\\worksheets\\", "sheet*.xml");

                foreach (string sheet_file in xl_sheet_files)
                {
                    string res_id   = GetResourceId(sheet_file);
                    string name     = GetWorksheetName(sheet_file, res_id);
                    short  sheet_id = GetWorksheetId(sheet_file, res_id);
                    Console.WriteLine("---------------------------" + sheet_file + "-------------------------------------");
                    Worksheet wrk = new Worksheet(shared_strings);
                    wrk.Load(res_id, sheet_id, name, sheet_file, shared_strings);
                    wrk.Number = (uint)Worksheets.Count;
                    Console.WriteLine("---------------------------------------------------------------------------------------");
                    Worksheets.Add(wrk);
                }
            } catch (Exception ex) {
                throw new FastXcelException("Error processing worksheets", ex);
            }
        }
Beispiel #3
0
        private void ProcessWorksheets()
        {
            try {
                Worksheets.Clear();
                string[] xl_sheet_files = Directory.GetFiles(temp_path+"\\xl\\worksheets\\", "sheet*.xml");

                foreach ( string sheet_file in xl_sheet_files ) {
                    string res_id = GetResourceId(sheet_file);
                    string name = GetWorksheetName(sheet_file, res_id);
                    short sheet_id = GetWorksheetId(sheet_file, res_id);
                    Console.WriteLine("---------------------------"+ sheet_file +"-------------------------------------");
                    Worksheet wrk =  new Worksheet( shared_strings );
                    wrk.Load( res_id, sheet_id, name, sheet_file, shared_strings );
                    wrk.Number = (uint)Worksheets.Count;
                    Console.WriteLine("---------------------------------------------------------------------------------------");
                    Worksheets.Add( wrk );
                }
            } catch ( Exception ex ) {
                throw new FastXcelException( "Error processing worksheets", ex );
            }
        }
Beispiel #4
0
        public short NewWorksheet( string name = "" )
        {
            try {

                System.Resources.ResourceManager resourceManager =
                    new System.Resources.ResourceManager("fastxcel.Resource", GetType().Assembly);

                var assembly = System.Reflection.Assembly.GetExecutingAssembly();

                short new_ws_number = (short)(Worksheets.Count+1);
                string res_id = "Re";

                Worksheet new_wrk = new Worksheet( shared_strings );

                if ( name == String.Empty )
                    name = "Worksheet"+Worksheets.Count.ToString();

                // First of all - create new xml file
                int num = 1;
                while ( File.Exists(temp_path+"\\xl\\worksheets\\sheet"+num.ToString()+".xml") )
                    ++num;
                string new_file_path = temp_path+"\\xl\\worksheets\\sheet"+num.ToString()+".xml";
                string resource_path = assembly.GetName().Name+".Resources.sheet_xml";

                BinaryReader br = new BinaryReader(assembly.GetManifestResourceStream(resource_path));
                long file_length = assembly.GetManifestResourceStream(resource_path).Length;
                byte[] inners = new byte[file_length];
                inners = br.ReadBytes((int)file_length);

                br.Close();

                FileStream fs = File.Create( new_file_path );
                BinaryWriter bw = new BinaryWriter( fs );

                bw.Write(inners);
                bw.Close();

                // Register relationship
                int res_id_num = xml_wb_rels.XmlElements.Count;

                AddNewRelationship(num, "rId" + res_id_num.ToString(), "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet");

                // Add into workbook.xml
                AddSheetInWorkbook( "rId" + res_id_num.ToString(), name, new_ws_number );

                // Finally
                new_wrk.Load( new_file_path, shared_strings );

                Worksheets.Add( new_wrk );

                return new_ws_number;
            } catch ( Exception ex ) {
                throw new FastXcelException( "Can't create new worksheet"+ex.Message, ex );
            }
        }