예제 #1
0
        //internal void wrDoсForm(string dir, string v, DateTime date, string mD5, int count, string strListRules)
        //{
        //    throw new NotImplementedException();
        //}

        /// <summary>
        /// wrDoc(str, obect[] obj) -- write data from array of objects to the Document in Excel
        /// </summary>
        /// <param name="str">form name; "str_F" format is also accounted</param>
        /// <param name="obg">data array to be written</param>
        /// <history>16.3.2016
        /// 26.3.2016 - output HDR_ form with time.Now in [1,1]
        ///  3.4.2016 - multiple line output support with last_name
        /// 13.4.2016 - Internal error message, when form not found
        /// 22.8.2016 - auditted: if(obj is Array); i0+1
        /// </history>
        public void wrDoc(string formName, params object[] obj)
        {
            Log.set("wrDoc(" + formName + ", obj[])");

            if (obj is Array)
            {
                int objLng = obj.Length;
                object[] _obj = obj;
                //--------------- not implemented yet
                if (obj[0] is Array)
                {

                }
            }
            //           Type ob = typeof(obj);  //.IsAssignableFrom(type); 

            Form frm = forms.Find(x => x.name == formName);
            if (frm == null) Msg.F("Document.wrDoc no form", formName, this.name);
            if (frm.col.Count != frm.row.Count) Msg.F("wrDoc Form corrupted"
                , formName, frm.row.Count, frm.col.Count);
            if (frm.col.Count != obj.Length) Msg.F("wrDoc wrong agroments", obj);
            if (frm.name == Form.last_name)
            {
                Body.AddRow(obj);
            }
            else
            {
                saveDoc();
                int lineInBodyToWrite = Form.nStr < 1 ? Body.iEOL() : Form.nStr;
                Excel.Range rng = FileOp.setRange(Sheet, lineInBodyToWrite);
                Document toc = getDoc();
                FileOp.CopyRng(toc.Wb, formName, rng);
                Body = FileOp.getSheetValue(Sheet);
                FileOp.saveRngValue(Body);
                int i = 0;
                foreach (var v in obj)
                {
                    int r = frm.row[i] + lineInBodyToWrite - 1;
                    int c = frm.col[i++];
                    Body[r, c] = v;
                }
                FileOp.saveRngValue(Body, 1, AutoFit: frm.AutoFit);
                Form.last_name = frm.name;
            }
            Log.exit();
        }
예제 #2
0
 /// <summary>
 /// Reset() - "Reset" of the Document. All contents of hes Excel Sheet erased, write Header form
 /// Reset("Now") - write DataTime.Now string in Cell [1,1]
 /// </summary>
 /// <history>9.1.2014
 /// 17.1.16 - полностью переписано с записью Шапки
 /// 16.3.16 - header name get from doc.forms[0]
 /// 26.3.16 - Reset("Now")
 /// 27.3.16 - bug fixed. Issue was: Reset named as a doc.name instead SheetN
 /// </history>
 public void Reset(string str = "")
 {
     Log.set("Reset(" + this.name + ")");
     Document toc = getDoc();
     this.Sheet = FileOp.SheetReset(this.Wb, this.SheetN);
     Excel.Range rng = FileOp.setRange(this.Sheet);
     if (this.forms.Count == 0) Msg.F("Document.Reset no HDR form", this.name);
     string myHDR_name = this.forms[0].name;
     FileOp.CopyRng(toc.Wb, myHDR_name, rng);
     this.Body = FileOp.getSheetValue(this.Sheet);
     if (str == "Now")
     {
         Body[1, 1] = Lib.timeStr();
         FileOp.setRange(this.Sheet);
         FileOp.saveRngValue(Body);
     }
     Log.exit();
 }