Esempio n. 1
0
        public void SetCellValue(string cell, string value, int hint_row = -1)
        {
            try
            {
                if (read_only)
                {
                    throw new Exception("Excel file is opened in read only mode and can't be modified!");
                }
                var p1 = sheet_data.IndexOf("r=\"" + cell + "\"", new SheetData.index {
                    row = hint_row
                });
                if (p1 == null)
                {
                    p1 = sheet_data.IndexOf("r=\"" + cell + "\"", null);
                }
                {
                    var p4 = sheet_data.IndexOf("/>", p1);
                    var p5 = sheet_data.IndexOf("<", p1);
                    if (p4 < p5)
                    {
                        sheet_data = sheet_data.Replace(p4, p4 + 2, " t=\"str\"><v>" + value + "</v></c>");
                        //sheet_data = sheet_data.Remove(p4, 2);
                        //sheet_data = sheet_data.Insert(p4, " t=\"str\"><v>" + value + "</v></c>");
                        return;
                    }
                }
                var p2 = sheet_data.IndexOf("<v>", p1).Add(3);
                var p3 = sheet_data.IndexOf("</v>", p2);
                {
                    sheet_data = sheet_data.Replace(p2, p3, value);
                }

                //sheet_data = sheet_data.Remove(p2, p3 - p2);
                //sheet_data = sheet_data.Insert(p2, value);

                p2 = sheet_data.IndexOf("t=\"s\"", p1).Add(3);
                if (p2 > p3)
                {
                    return;
                }
                p3 = sheet_data.IndexOf("\"", p2);
                {
                    sheet_data = sheet_data.Replace(p2, p3, "str");
                }
                //sheet_data = sheet_data.Remove(p2, p3 - p2);
                //sheet_data = sheet_data.Insert(p2, "str");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in Excell.SetCellValue: (" + cell + ") : " + ex.Message);
                //throw;
            }
        }