internal WordCellRange(WordTable WordTable,int startRow,int startColumn,int endRow,int endColumn)
 {
     this.WordTable=WordTable;
     this.startColumn=startColumn;
     this.startRow=startRow;
     this.endColumn=endColumn;
     this.endRow=endRow;
 }
Esempio n. 2
0
 internal WordRow(WordTable WordTable,int index)
 {
     this.WordTable=WordTable;
     this.index=index;
     this.startColumn=0;
     this.endColumn=this.WordTable.columns-1;
     this.startRow=index;
     this.endRow=index;
 }
 internal WordColumn(WordTable WordTable,int index)
 {
     this.WordTable=WordTable;
     this.index=index;
     this.startColumn=index;
     this.endColumn=index;
     this.startRow=0;
     this.endRow=this.WordTable.rows-1;
 }
 /// <summary>
 /// Нормальный текст на 2 столбца
 /// </summary>
 /// <param name="rt"></param>
 /// <param name="text"></param>
 /// <param name="curRow"></param>
 internal static void H3Write(WordTable rt, string text, ref int curRow)
 {
     rt.Rows[curRow][0].ColSpan	= 2;
     rt.Rows[curRow][0].SetBorders(Color.Black, 1, false, true, true, true);
     rt.Rows[curRow][0].SetFontBackgroundColor(Color.White);
     rt.Rows[curRow][0].SetFont(normal);
     rt.Rows[curRow][0].Write(text);
     curRow++;
 }
 /// <summary>
 /// Большой заголовок, через 2 столбца ячейки
 /// </summary>
 /// <param name="rt"></param>
 /// <param name="text"></param>
 /// <param name="curRow"></param>
 internal static void H1Write(WordTable rt, string text, ref int curRow)
 {
     rt.Rows[curRow].SetRowHeight(420);
     rt.Rows[curRow][0].ColSpan	= 2;
     rt.Rows[curRow][0].SetCellPadding(45)	;
     rt.Rows[curRow][0].SetBorders(Color.Black, 1, true, true, true, true);
     rt.Rows[curRow][0].SetFont(caption);
     rt.Rows[curRow][0].SetContentAlignment(ContentAlignment.BottomLeft);
     rt.Rows[curRow][0].Write(text);
     curRow++;
 }
Esempio n. 6
0
        private void PopulateTable()
        {
            //create dict
            Table = new WordTable();

            List <string> words = GetWords();

            //List<string> words = new List<string>();
            //words.Add("ANGELA");
            //words.Add("JIMMY");
            //words.Add("LARRY");
            //words.Add("JACK");
            //words.Add("JILL");
            //words.Add("MARK");
            //words.Add("AMY");


            foreach (string word in words)
            {
                LetterTable letterTable = new LetterTable();

                foreach (char letter in word)
                {
                    if (!letterTable.ContainsKey(letter))
                    {
                        List <string> intersectingWords = new List <string>();

                        foreach (string w in words)
                        {
                            if (w.IndexOf(letter) > -1)
                            {
                                if (!intersectingWords.Contains(w))
                                {
                                    intersectingWords.Add(w);
                                }
                            }
                        }
                        letterTable.Add(letter, intersectingWords);
                    }
                }

                Table.Add(word, letterTable);
            }
        }
Esempio n. 7
0
        private static void SetWeeksHeaderTable(WordTable table)
        {
            int    i     = 1;
            string week1 = "I" + Environment.NewLine + "Н Е Д Е Л Я";

            table.Cell(i, 0).Write(week1);

            WordCellRange wsr = table.CellRange(i, 0, i + 5, 0);

            wsr.MergeCells();

            i = i + 6;

            string week2 = "II" + Environment.NewLine + "Н Е Д Е Л Я";

            table.Cell(i, 0).Write(week2);

            wsr = table.CellRange(i, 0, i + 5, 0);
            wsr.MergeCells();
        }
Esempio n. 8
0
        public void tianjiaafter()//后向添加数据存储到数据库
        {
            int       cur_id        = int.Parse(Request.Form["id"]);
            WordTable cur_wordTable = db.WordTable.Find(cur_id);
            WordTable wordTable     = new WordTable();

            if (ModelState.IsValid)
            {
                var list1 = db.WordTable.Where(ad => ad.newid > cur_wordTable.newid).OrderBy(ad => ad.newid);
                foreach (var i in list1)
                {
                    i.newid          += 1;
                    db.Entry(i).State = EntityState.Modified;
                }
                int max_id = db.WordTable.Max(d => d.id);
                wordTable.id        = max_id + 1;;
                wordTable.newid     = cur_wordTable.newid + 1;
                wordTable.wordName  = Request.Form["txtName"];
                wordTable.character = int.Parse(Request.Form["txtSeqNo"].Split('-').Last());
                db.WordTable.Add(wordTable);
                db.SaveChanges();
            }
        }
Esempio n. 9
0
        public ActionResult Edit([Bind(Include = "isNeibu,archiveID,juanneiSeqNo,fileNo,fileTitle1,resUnit1,pageNo,bianzhiDate,remarks")] LicenceFiles licenceFiles, int ID, string action)
        {
            long archiveID = long.Parse(Request.Form["archiveID"]);

            if (action == "保存修改")
            {
                if (ModelState.IsValid)
                {
                    archiveID                    = long.Parse(Request.Form["archiveID"]);
                    ViewBag.archiveID            = archiveID;//记得传回视图
                    ViewBag.fileTitle            = licenceFiles.fileTitle;
                    ViewBag.resUnit              = licenceFiles.resUnit;
                    licenceFiles.ID              = ID;
                    licenceFiles.fileTitle       = Request.Form["fileTitle1"];
                    licenceFiles.resUnit         = Request.Form["resUnit1"];
                    db.Entry(licenceFiles).State = EntityState.Modified;
                    db.SaveChanges();
                    return(Content("<script >alert('修改成功!');window.location.href='/LicenceFiles/Index?id1=2" + "&id=" + ID + "&archiveID=" + archiveID + "';</script >"));
                }
            }
            if (action == "删除词条")
            {
                int       id        = int.Parse(Request.Form["no1"].Split('-').First());
                WordTable wordtable = db.WordTable.Find(id);
                db.WordTable.Remove(wordtable);
                var list1 = db.WordTable.Where(ad => ad.newid > wordtable.newid).OrderBy(ad => ad.newid);
                foreach (var i in list1)
                {
                    i.newid          -= 1;
                    db.Entry(i).State = EntityState.Modified;
                }
                db.SaveChanges();
                return(Content("<script >alert('删除成功!');window.location.href='/LicenceFiles/Index?id1=2" + "&id=" + ID + "&archiveID=" + archiveID + "';</script >"));
            }
            return(View());
        }
Esempio n. 10
0
 private void NewCell(WordTable table, int row, int col, string text, Font font)
 {
     table.Cell(row, col).Write(text);
     table.Cell(row, col).SetFont(font);
     table.Cell(row, col).SetBorders(Color.Black, 1, true, true, true, true);
 }
Esempio n. 11
0
        void ProcessTable(Body Body, Table Table)
        {
            TableRow[]      TableRows  = Table.Elements <TableRow>().ToArray();
            TableProperties TableProps = Table.Elements <TableProperties>().First();
            TableGrid       TableGrid  = Table.Elements <TableGrid>().First();

            // TODO: Change exception types
            if (TableRows.Length != 1)
            {
                for (int j = 0; j < TableRows.Length; j++)
                {
                    TableCell[] Cells = TableRows[j].Elements <TableCell>().ToArray();

                    for (int i = 0; i < Cells.Length; i++)
                    {
                        Process(Body, Cells[i]);
                    }
                }
            }
            else
            {
                TableRow    TemplateRow = TableRows[0];
                TableCell[] Cells       = TemplateRow.Elements <TableCell>().ToArray();

                WordTable WTable = WordTableContext.Begin();
                for (int i = 0; i < Cells.Length; i++)
                {
                    WTable.BeginColumn();
                    Process(Body, Cells[i]);
                    WTable.EndColumn();
                }

                WordTable.Column[] Columns = WTable.GetColumns();
                WordTableContext.End();

                int RowCount = 0;

                if (Columns.Length > 0)
                {
                    RowCount = Columns.Select(C => (C.RefArray?.Count - 1) ?? 0).Max();
                }

                List <TableCell> TableCells = new List <TableCell>();

                for (int i = 0; i < RowCount; i++)
                {
                    TableCells.Clear();

                    for (int j = 0; j < Columns.Length; j++)
                    {
                        JArray RefArray = Columns[j].RefArray;
                        if (RefArray == null)
                        {
                            continue;
                        }

                        if (i < RefArray.Count - 1)
                        {
                            object Val = RefArray[i + 1][Columns[j].Identifier].Value <JValue>().Value;

                            // TODO: Handle stuff other than strings?
                            TableCells.Add(GenerateCell(Val.ToString()));
                        }
                        else
                        {
                            TableCells.Add(GenerateCell(""));
                        }
                    }

                    Table.AppendChild(GenerateRow(TableCells.ToArray()));
                }
            }
        }
Esempio n. 12
0
        private void ParseWordFile(object FileName)
        {
            object rOnly       = true;
            object SaveChanges = false;
            object MissingObj  = System.Reflection.Missing.Value;

            Word.Application app   = new Word.Application();
            Word.Document    doc   = null;
            Word.Range       range = null;
            try
            {
                doc = app.Documents.Open(ref FileName, ref MissingObj, ref rOnly, ref MissingObj,
                                         ref MissingObj, ref MissingObj, ref MissingObj, ref MissingObj,
                                         ref MissingObj, ref MissingObj, ref MissingObj, ref MissingObj,
                                         ref MissingObj, ref MissingObj, ref MissingObj, ref MissingObj);

                int    indexTable = -1;//1
                string s1 = null, s2 = null, s3 = null;

                foreach (Word.Table WordTable in doc.Tables)
                {
                    ////foreach (Word.Column columns in WordTable.Columns)
                    ////{
                    //try
                    //{
                    //    foreach (Word.Row row in WordTable.Rows)
                    //    {
                    //        try
                    //        {
                    //            foreach (Word.Cell cell in row.Cells)
                    //                try
                    //                {
                    //                    Console.WriteLine($"[{cell.RowIndex}:{cell.ColumnIndex}]:{cell.Range.Text}");

                    //                }
                    //                catch (Exception ex)
                    //                {

                    //                }
                    //        }
                    //        catch (Exception ex)
                    //        {

                    //        }
                    //    }
                    //}
                    //catch (Exception ex)
                    //{
                    //}
                    ////}

                    if (indexTable == 1)
                    {
                        if (WordTable.Rows.Count > 10)
                        {
                            //s1 = WordTable.Cell(10, 2).Range.Text;
                            s1 = WordTable.Cell(1, 2).Range.Text;
                            s1 = s1.Replace("\r\a", string.Empty);
                            //Console.WriteLine(s1);
                        }

                        //if (WordTable.Rows.Count > 20)
                        if (WordTable.Rows.Count > 11)
                        {
                            //s2 = WordTable.Cell(20, 3).Range.Text;
                            s2 = WordTable.Cell(11, 3).Range.Text;
                            s2 = s2.Replace("\r\a", string.Empty);
                            //Console.WriteLine(s2);
                        }
                    }
                    else if (indexTable == 2)
                    {
                        if (WordTable.Rows.Count >= 2)
                        {
                            s3 = WordTable.Cell(2, 3).Range.Text;
                            s3 = s3.Replace("\r\a", string.Empty);
                            //Console.WriteLine(s3);
                        }
                    }
                    indexTable++;
                }

                if (doc != null)
                {
                    doc.Close(ref SaveChanges);
                    doc = null;
                }
                if (range != null)
                {
                    Marshal.ReleaseComObject(range);
                    range = null;
                }
                if (app != null)
                {
                    app.Quit();
                    Marshal.ReleaseComObject(app);
                    app = null;
                }


                if (s1 != null && s2 != null && s3 != null)
                {
                    parserText(s1, s2, s3, FileName.ToString(), typeFile.word, 0);
                }
                else
                {
                    Console.WriteLine("Not Find");
                }
                //Console.WriteLine();
            }
            catch (Exception ex)
            {
                /* Обработка исключений */
            }
            finally
            {
                /* Очистка неуправляемых ресурсов */
                if (doc != null)
                {
                    doc.Close(ref SaveChanges);
                }
                if (range != null)
                {
                    Marshal.ReleaseComObject(range);
                    range = null;
                }
                if (app != null)
                {
                    app.Quit();
                    Marshal.ReleaseComObject(app);
                    app = null;
                }
            }
        }
 /// <summary>
 /// Creates a new WordTable.
 /// </summary>
 /// <param name="DefaultFont"></param>
 /// <param name="DefaultForegroundColor"></param>
 /// <param name="rows"></param>
 /// <param name="columns"></param>
 /// <param name="padding"></param>
 /// <returns></returns>
 public WordTable NewTable(Font DefaultFont,Color DefaultForegroundColor,int rows,int columns,int padding)
 {
     WordTable ta=new WordTable(this.WordDocument,rows,columns,padding);
     foreach (WordCell rc in ta.cells.Values)
     {
         rc.SetForegroundColor(DefaultForegroundColor);
         rc.SetFont(DefaultFont);
     }
     return ta;
 }
Esempio n. 14
0
        private void FillLessons(WordTable table, int monthStart, int row, List <ScheduleLesson> tmp, Week week1, Week week2)
        {
            int column = 1;

            for (int counterDay = 1; counterDay <= 6; counterDay++)
            {
                column = 1;
                for (int counterMonth = monthStart; counterMonth < monthStart + 5; counterMonth++)
                {
                    List <int> numbers = (from x in tmp
                                          from p in x.Dates
                                          where x.Day == (ScheduleClasses.Day)counterDay &&
                                          p.Month == counterMonth && (x.Week == week1 || x.Week == week2)
                                          select p.Day).Distinct().OrderBy(e => e).ToList();

                    foreach (int day in numbers)
                    {
                        table.Cell(row, column).WriteLine();
                        table.Cell(row, column).Write(day.ToString());
                    }
                    column++;
                }

                List <ScheduleLesson> query1 = (from x in tmp
                                                from p in x.Dates
                                                where x.Day == (ScheduleClasses.Day)counterDay && (x.Week == week1 || x.Week == week2)
                                                select x).ToList();

                List <int> Hours = (from x in query1 select x.Hour).Distinct().OrderBy(e => e).ToList();

                foreach (int hour in Hours)
                {
                    string str = "";
                    str = ScheduleTime.GetHourDiscription(hour);
                    table.Cell(row, 7).Write(str);
                    table.Cell(row, 7).WriteLine();
                }

                for (int i = 0; i < Hours.Count; i++)
                {
                    List <ScheduleLesson> t1 = query1.Where(x => x.Hour == Hours[i] && x.Week == week1).ToList();
                    List <ScheduleLesson> t2 = query1.Where(x => x.Hour == Hours[i] && x.Week == week2).ToList();

                    ScheduleLesson lesson  = (t1.Count > 0) ? t1.First() : null;
                    ScheduleLesson lesson2 = (t2.Count > 0) ? t2.First() : null;

                    if (lesson != null && lesson2 != null && lesson.IsEqual(lesson2))
                    {
                        WriteLesson(table, row, lesson, false);


                        if (i + 1 < Hours.Count)
                        {
                            List <ScheduleLesson> Next1 = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week1).ToList();
                            ScheduleLesson        next1 = (t1.Count > 0) ? t1.First() : null;

                            List <ScheduleLesson> Next2 = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week2).ToList();
                            ScheduleLesson        next2 = (t1.Count > 0) ? t1.First() : null;


                            if (next1 != null && next2 != null && next1.IsEqual(next2) && lesson.IsEqual(next1))
                            {
                                i++;
                            }
                        }
                    }
                    else
                    {
                        if (lesson != null)
                        {
                            if (lesson2 == null)
                            {
                                WriteLesson(table, row, lesson, false);
                            }
                            else
                            {
                                WriteLesson(table, row, lesson, true);
                            }

                            if (i + 1 < Hours.Count)
                            {
                                List <ScheduleLesson> Next = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week1).ToList();
                                ScheduleLesson        next = (Next.Count > 0) ? Next.First() : null;

                                if (next != null && lesson.IsEqual(next))
                                {
                                    i++;
                                }
                            }
                        }

                        if (lesson2 != null)
                        {
                            if (lesson == null)
                            {
                                WriteLesson(table, row, lesson2, false);
                            }
                            else
                            {
                                WriteLesson(table, row, lesson2, true);
                            }

                            if (i + 1 < Hours.Count)
                            {
                                List <ScheduleLesson> Next = query1.Where(x => x.Hour == Hours[i + 1] && x.Week == week2).ToList();
                                ScheduleLesson        next = (Next.Count > 0) ? Next.First() : null;

                                if (next != null && lesson2.IsEqual(next))
                                {
                                    i++;
                                }
                            }
                        }
                    }
                }
                row++;
            }
        }
        /// <summary>
        /// 4 столбца все жирные
        /// </summary>
        internal static void H7Write(WordTable rt, string text1, string text2, string text3, string text4, ref int curRow)
        {
            rt.Rows[curRow][0].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][0].SetFont(normalBold);
            rt.Rows[curRow][0].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][0].Write(text1);

            rt.Rows[curRow][1].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][1].SetFont(normal);
            rt.Rows[curRow][1].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][1].Write(text2);

            rt.Rows[curRow][2].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][2].SetFont(normal);
            rt.Rows[curRow][2].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][2].Write(text3);

            rt.Rows[curRow][3].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][3].SetFont(normal);
            rt.Rows[curRow][3].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][3].Write(text4);
            curRow++;
        }
        internal static void H8Write(WordTable rt, string text1, string text2, string text3, string text4, ref int curRow)
        {
            rt.Rows[curRow][0].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][0].SetFont(normalBold);
            rt.Rows[curRow][0].SetContentAlignment(ContentAlignment.MiddleCenter);
            rt.Rows[curRow][0].SetFontBackgroundColor(Color.DarkGray);
            rt.Rows[curRow][0].SetBackgroundColor(Color.DarkGray);
            rt.Rows[curRow][0].Write(text1);

            rt.Rows[curRow][1].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][1].SetFont(normal);
            rt.Rows[curRow][1].SetContentAlignment(ContentAlignment.TopLeft);
            rt.Rows[curRow][1].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][1].Write(text2);

            rt.Rows[curRow][2].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][2].SetFont(normal);
            rt.Rows[curRow][2].SetContentAlignment(ContentAlignment.TopLeft);
            rt.Rows[curRow][2].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][2].Write(text3);

            rt.Rows[curRow][3].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][3].SetFont(normal);
            rt.Rows[curRow][3].SetContentAlignment(ContentAlignment.TopLeft);
            rt.Rows[curRow][3].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][3].Write(text4);
            curRow++;
        }
        /// <summary>
        /// Левый столбец жирный с фоном, правый - обычный без фона
        /// </summary>
        /// <param name="rt"></param>
        /// <param name="leftColumn"></param>
        /// <param name="rightColumn"></param>
        /// <param name="curRow"></param>
        internal static void H4Write(WordTable rt, string leftColumn, string rightColumn, ref int curRow)
        {
            rt.Rows[curRow][0].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][0].SetFont(normalBold);
            rt.Rows[curRow][0].SetBackgroundColor(Color.DarkGray);
            rt.Rows[curRow][0].SetFontBackgroundColor(Color.DarkGray);
            rt.Rows[curRow][0].Write(leftColumn);

            rt.Rows[curRow][1].SetBorders(Color.Black, 1, true, true, true, true);
            rt.Rows[curRow][1].SetFont(normal);
            rt.Rows[curRow][1].SetFontBackgroundColor(Color.White);
            rt.Rows[curRow][1].Write(rightColumn);
            curRow++;
        }
Esempio n. 18
0
        public DataType GetObject(string Token, TokenParameters TokenParams, out object Obj)
        {
            string[] FullName = Token.Split('.');
            Obj = Data;

            if (FullName.Length == 1 & FullName[0].StartsWith("$"))
            {
                return(GetSpecialObject(FullName[0], out Obj));
            }

            for (int i = 0; i < FullName.Length; i++)
            {
                if (FullName[i].StartsWith("$"))
                {
                    WordTable CurTable   = WordTableContext.GetCurrent();
                    string    TableToken = string.Join(".", FullName.Take(i).ToArray());

                    WordTable.Column Col = CurTable.GetCurrentColumn();
                    Col.Identifier = FullName[i].Substring(1);
                    //Col.RefArrayToken = TableToken;


                    DataType TableTokenDataType = GetObject(TableToken, TokenParams, out object _Obj);
                    if (_Obj is JArray TableObj)
                    {
                        JToken ColumnDefinition = TableObj[0][Col.Identifier];

                        Col.RefArray = TableObj;
                        Col.Text     = ColumnDefinition["text"].Value <string>();
                        Col.Style    = ColumnDefinition["style"].Value <string>();
                    }
                    else
                    {
                        throw new Exception(string.Format("Expected array, got '{0}' for token '{1}'", TableTokenDataType, TableToken));
                    }

                    Obj = Col.Text;
                    return(DataType.String);
                }

                if (Obj is JObject JRoot)
                {
                    JToken JToken = JRoot.GetValue(FullName[i]);

                    if (JToken == null)
                    {
                        Obj = null;
                    }
                    else if (JToken is JValue JValue)
                    {
                        Obj = JValue.Value;
                    }
                    else if (JToken is JObject)
                    {
                        Obj = JToken.Value <JObject>();
                    }
                    else if (JToken is JArray)
                    {
                        Obj = JToken.Value <JArray>();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    string Cur = string.Join(".", FullName.Take(i).ToArray());
                    throw new Exception(string.Format("Could not find value for token '{0}', got '{1}' of value '{2}'", Token, Cur, Obj));
                }
            }

            if (Obj == null)
            {
                if (TokenParams != null && TokenParams.Defined("null"))
                {
                    Obj = TokenParams.Get <string>("null");
                    return(DataType.String);
                }

                return(DataType.None);
            }
            else if (Obj is JObject JObject)
            {
                if (JObject.TryGetValue("__type", out JToken TypeToken) && JObject.TryGetValue("__data", out JToken DataToken))
                {
                    Obj = new EmbeddedData(TypeToken, DataToken);
                    return(DataType.EmbeddedData);
                }

                return(DataType.Object);
            }
            else if (Obj is JArray)
            {
                return(DataType.Array);
            }
            else if (Obj is string RootStr)
            {
                // TODO: Fix eventually
                Obj = RootStr.Trim().Replace("\r", "").Replace("\n", " ").Replace("\t", " ");

                /*if (RootStr.Contains("\n"))
                 *      Debugger.Break();*/

                return(DataType.String);
            }
            else
            {
                throw new NotImplementedException();
            }
        }