Пример #1
0
        private static void CreateSimpleTable(Document doc, DocumentBuilder builder, List <GoodsModel> list)
        {
            Table table = builder.StartTable();

            #region 表头
            string[] titles = new string[] { "序号", "货品名称", "货品类型", "存放位置", "数量" };
            int[]    lens   = new int[] { 10, 25, 25, 25, 15 };
            for (int i = 0; i < 5; i++)
            {
                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[i]); //列宽-百分比
                builder.CellFormat.Shading.BackgroundPatternColor = Color.LightGray;     //背景色-灰色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;           //对齐-居中
                builder.Write(titles[i]);                                                //写入内容
            }
            builder.EndRow();                                                            //结束行
            #endregion

            #region 内容
            for (int i = 0; i < list.Count; i++)
            {
                GoodsModel model = list[i];

                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[0]); //列宽
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;         //背景色-白色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;           //对齐-居中
                builder.Write((i + 1).ToString());                                       //写入内容

                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[1]); //列宽
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;         //背景色-白色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;             //对齐-靠左
                builder.Write(model.GoodsName);                                          //写入内容

                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[2]); //列宽
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;         //背景色-白色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;           //对齐-居中
                builder.Write(model.GoodsType);                                          //写入内容

                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[3]); //列宽
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;         //背景色-白色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;            //对齐-靠右
                builder.Write(model.Location);                                           //写入内容

                builder.InsertCell();                                                    //插入单元格
                builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(lens[4]); //列宽
                builder.CellFormat.Shading.BackgroundPatternColor = Color.White;         //背景色-白色
                builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;           //对齐-居中
                builder.Write((model.GoodsNum).ToString());                              //写入内容

                builder.EndRow();                                                        //结束行
            }
            #endregion

            builder.EndTable();//结束表格
        }
Пример #2
0
        private static List <GoodsModel> MakeListData()
        {
            List <GoodsModel> list = new List <GoodsModel>();

            GoodsModel model1 = new GoodsModel {
                GoodsName = "矿泉水", GoodsType = "酒水饮料", Location = "1号库", GoodsNum = 100
            };
            GoodsModel model2 = new GoodsModel {
                GoodsName = "纯净水", GoodsType = "酒水饮料", Location = "1号库", GoodsNum = 400
            };
            GoodsModel model3 = new GoodsModel {
                GoodsName = "苏打水", GoodsType = "酒水饮料", Location = "1号库", GoodsNum = 200
            };
            GoodsModel model4 = new GoodsModel {
                GoodsName = "啤酒", GoodsType = "酒水饮料", Location = "1号库", GoodsNum = 100
            };

            list.Add(model1);
            list.Add(model2);
            list.Add(model3);
            list.Add(model4);
            return(list);
        }