Ejemplo n.º 1
0
        void printLable()
        {
            string path = Directory.GetCurrentDirectory();

            Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook   wb  = null;
            wb = oXL.Workbooks.Open(path + @"/../../xls/cleancut/7 标签-清洁分切.xlsx");
            _Worksheet my = wb.Worksheets[wb.Worksheets.Count];

            my.Select();
            my.Cells[2, 2].Value = cb膜代码.Text;
            my.Cells[3, 2].Value = tb批号.Text;
            my.Cells[4, 2].Value = tb米.Text + "米;  " + tbKg.Text + "Kg";
            my.Cells[5, 2].Value = cb原膜代码.Text;
            my.Cells[6, 2].Value = String.Format("{0} {1}", dtp分切日期.Value.ToString("yyyy/MM/dd"),
                                                 cb白班.Checked ? "白班☑ 夜班□" : "白班□ 夜班☑");

            my = wb.Worksheets[1];
            my.Select();
            oXL.Visible = false;
            my.PrintOut();
            // 关闭文件,false表示不保存
            wb.Close(false);
            // 关闭Excel进程
            oXL.Quit();
            // 释放COM资源
            Marshal.ReleaseComObject(wb);
            Marshal.ReleaseComObject(oXL);
            wb  = null;
            oXL = null;
        }
Ejemplo n.º 2
0
        public Task Send(SysData.DataTable table, string excelTemplatePath, bool directlyPrint, int startRowIndex = 2)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (string.IsNullOrEmpty(excelTemplatePath))
            {
                throw new ArgumentNullException("excelTemplatePath", "You must specify path to the excel workbook");
            }
            Task tsk = Task.Run(() =>
            {
                _Application excelApp    = null;
                Workbooks excelWorkbooks = null;
                _Workbook excelWorkbook  = null;
                _Worksheet excelSheet    = null;
                string fileNamePath      = excelTemplatePath;;

                //Start Excel and create new workbook from the template
                excelApp = StartExcel();
                try
                {
                    excelWorkbooks = excelApp.Workbooks;
                    excelWorkbook  = excelWorkbooks.Open(fileNamePath);
                    excelSheet     = excelWorkbook.Sheets[1];
                    //Insert the DataGridView into the excel spreadsheet
                    TableToExcelSheet(table, excelSheet, startRowIndex, 1);
                    //if visible , then exit so user can see it, otherwise save and exit

                    if (directlyPrint)
                    {
                        //bool okPrint = objExcel.Dialogs[XlBuiltInDialog.xlDialogPrint].Show();
                        // if (!okPrint)
                        //{
                        //    objWorkbook.Close(false);
                        //    return;
                        //}
                        excelSheet.PrintOut();
                        //excelWorkbook.Close(false);
                        excelApp.DisplayAlerts = false;
                        excelApp.Quit();
                        ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
                        return;
                    }
                    excelApp.Visible = true;
                    ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
                }
                catch (Exception)
                {
                    ForceExcleToQuit(excelApp);
                    ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
                    throw;
                }
            }

                                );

            return(tsk);
        }
Ejemplo n.º 3
0
        void printLable(bool flag)
        {
            string path = Directory.GetCurrentDirectory();

            Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook   wb  = null;
            if (flag)
            {
                wb = oXL.Workbooks.Open(path + @"/../../xls/LDPEBag/LDPE 制袋内包标签.xlsx");
            }
            else
            {
                wb = oXL.Workbooks.Open(path + @"/../../xls/LDPEBag/LDPE 制袋外包标签.xlsx");
            }
            _Worksheet my = wb.Worksheets[wb.Worksheets.Count];

            my.Select();
            my.Cells[1, 2].Value  = tc产品名称.Text;
            my.Cells[2, 2].Value  = tc产品编码.Text;
            my.Cells[3, 2].Value  = tc产品规格.Text;
            my.Cells[4, 2].Value  = tc产品批号.Text;
            my.Cells[5, 2].Value  = dc生产日期.Value.ToString("yyyy/MM/dd");
            my.Cells[6, 2].Value  = dc有效期至.Value.ToString("yyyy/MM");
            my.Cells[7, 2].Value  = tc数量.Text;
            my.Cells[8, 2].Value  = tc包装序号.Text;
            my.Cells[9, 2].Value  = tc毛重.Text;
            my.Cells[10, 2].Value = tc箱体规格.Text;
            my.Cells[11, 2].Value = tc注册证号.Text;


            my.Cells[1, 5].Value  = teName.Text;
            my.Cells[2, 5].Value  = teCode.Text;
            my.Cells[3, 5].Value  = teSize.Text;
            my.Cells[4, 5].Value  = teBatch.Text;
            my.Cells[5, 5].Value  = deMfg.Value.ToString("dd/MM/yyyy");
            my.Cells[6, 5].Value  = deExpiry.Value.ToString("MM/yyyy");
            my.Cells[7, 5].Value  = teQuantity.Text;
            my.Cells[8, 5].Value  = tePack.Text;
            my.Cells[9, 5].Value  = tegross.Text;
            my.Cells[10, 5].Value = teCarton.Text;

            my = wb.Worksheets[c标签模板.SelectedIndex + 1];
            my.Select();
            oXL.Visible = false;
            my.PrintOut();
            // 关闭文件,false表示不保存
            wb.Close(false);
            // 关闭Excel进程
            oXL.Quit();
            // 释放COM资源
            Marshal.ReleaseComObject(wb);
            Marshal.ReleaseComObject(oXL);
            wb  = null;
            oXL = null;
        }
Ejemplo n.º 4
0
        private void printLable()
        {
            string path = Directory.GetCurrentDirectory();

            Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            //File.Copy(@"../../xls/Extrusion/吹膜标签.xlsx", path + @"/label.xlsx", true);
            Microsoft.Office.Interop.Excel._Workbook wb = oXL.Workbooks.Open(path + @"/../../xls/Extrusion/吹膜标签.xlsx");
            _Worksheet my = wb.Worksheets[wb.Worksheets.Count];

            oXL.Visible          = false;
            my.Cells[1, 2].Value = cmb膜代码.SelectedItem;
            my.Select();
            my.Cells[2, 2].Value = tc批号.Text;
            my.Cells[3, 2].Value = tc数量米.Text + "米;" + tc数量KG.Text + "KG";
            my.Cells[4, 2].Value = dc日期.Value.ToShortDateString() + "     " +
                                   (cc班次.SelectedItem.ToString() == "白班" ? "白班" : "夜班");

            my.Cells[6, 2].Value  = tc产品名称.Text;
            my.Cells[7, 2].Value  = tc产品编码.Text;
            my.Cells[8, 2].Value  = tc产品规格.Text;
            my.Cells[9, 2].Value  = tc产品批号.Text;
            my.Cells[10, 2].Value = dc生产日期.Value.ToString("yyyy/MM/dd");
            my.Cells[11, 2].Value = dc有效期至.Value.ToString("yyyy/MM/dd");
            my.Cells[12, 2].Value = tc数量.Text;
            my.Cells[13, 2].Value = tc包装序号.Text;
            my.Cells[15, 2].Value = tc注册证号.Text;
            my.Cells[16, 2].Value = tc毛重.Text;
            my.Cells[17, 2].Value = tc箱体规格.Text;
            my.Cells[6, 5].Value  = teName.Text;
            my.Cells[7, 5].Value  = teCode.Text;
            my.Cells[8, 5].Value  = teSize.Text;
            my.Cells[9, 5].Value  = teBatch.Text;
            my.Cells[10, 5].Value = deMfg.Value.ToString("yyyy/MM/dd");
            my.Cells[11, 5].Value = deExpiry.Value.ToString("yyyy/MM/dd");
            my.Cells[12, 5].Value = teQuantity.Text;
            my.Cells[13, 5].Value = tePack.Text;
            my.Cells[15, 6].Value = teCFDA.Text;
            my.Cells[16, 6].Value = teGross.Text;
            my.Cells[17, 6].Value = teCarton.Text;

            my = wb.Worksheets[c标签模板.SelectedIndex + 1];
            my.Select();

            my.PrintOut();

            wb.Close(false);
            oXL.Quit();
            Marshal.ReleaseComObject(wb);
            Marshal.ReleaseComObject(oXL);
            wb  = null;
            oXL = null;
        }
Ejemplo n.º 5
0
        public void SendTable(SysData.DataTable table, string excelTemplatePath, string pdfFilePath)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (string.IsNullOrEmpty(excelTemplatePath))
            {
                throw new ArgumentNullException("excelTemplatePath", "You must specify path to the excel workbook");
            }
            if (string.IsNullOrEmpty(pdfFilePath))
            {
                throw new ArgumentNullException("pdfFilePath", "You must specify path to the excel workbook");
            }
            _Application excelApp       = null;
            Workbooks    excelWorkbooks = null;
            _Workbook    excelWorkbook  = null;
            _Worksheet   excelSheet     = null;
            string       fileNamePath   = excelTemplatePath;;
            bool         showExcel      = Properties.Settings.Default.ShowReports;

            //Start Excel and create new workbook from the template
            excelApp = StartExcel();
            try
            {
                excelWorkbooks = excelApp.Workbooks;
                excelWorkbook  = excelWorkbooks.Open(fileNamePath);
                excelSheet     = excelWorkbook.Sheets[1];
                //Insert the DataGridView into the excel spreadsheet
                TableToExcelSheet(table, excelSheet, 3, 1);
                if (!showExcel)
                {
                    excelSheet.PrintOut();
                    excelApp.DisplayAlerts = false;
                    excelApp.Quit();
                    ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
                    return;
                }
                excelApp.Visible = true;
                ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
            }
            catch (Exception ex)
            {
                Helper.LogOnly(ex);
                ForceExcleToQuit(excelApp);
                ReleaseResources(excelApp, excelWorkbooks, excelWorkbook, excelSheet);
                throw;
            }
        }
Ejemplo n.º 6
0
        public static void printLable(int id)
        {
            string           sql = "select * from 标签 where ID={0}";
            OleDbDataAdapter da  = new OleDbDataAdapter(String.Format(sql, id), mySystem.Parameter.connOle);

            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("未找到标签信息,无法打印");
                return;
            }
            DataRow dr   = dt.Rows[0];
            string  path = Directory.GetCurrentDirectory();

            Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            //File.Copy(@"../../xls/Extrusion/吹膜标签.xlsx", path + @"/label.xlsx", true);
            Microsoft.Office.Interop.Excel._Workbook wb = oXL.Workbooks.Open(path + @"/../../xls/Extrusion/吹膜标签.xlsx");
            _Worksheet my = wb.Worksheets[wb.Worksheets.Count];

            my.Cells[1, 2].Value = dr["膜代码"];
            my.Select();
            my.Cells[2, 2].Value = dr["批号中文"];
            my.Cells[3, 2].Value = dr["数量米"] + "米;" + dr["数量千克"] + "KG";
            my.Cells[4, 2].Value = Convert.ToDateTime(dr["日期中文"]).ToString("yyyy/MM/dd") + "     " +
                                   (dr["班次中文"]);

            my.Cells[6, 2].Value  = dr["产品名称中文"];
            my.Cells[7, 2].Value  = dr["产品编码中文"];
            my.Cells[8, 2].Value  = dr["产品规格中文"];
            my.Cells[9, 2].Value  = dr["产品批号中文"];
            my.Cells[10, 2].Value = Convert.ToDateTime(dr["生产日期中文"]).ToString("yyyy/MM/dd");
            my.Cells[11, 2].Value = Convert.ToDateTime(dr["有效期至中文"]).ToString("yyyy/MM/dd");
            my.Cells[12, 2].Value = dr["数量中文"];
            my.Cells[13, 2].Value = dr["包装序号中文"];
            my.Cells[15, 2].Value = dr["注册证号中文"];
            my.Cells[16, 2].Value = dr["毛重中文"];
            my.Cells[17, 2].Value = dr["箱体规格中文"];
            my.Cells[6, 5].Value  = dr["Name_E"];
            my.Cells[7, 5].Value  = dr["Code_E"];
            my.Cells[8, 5].Value  = dr["Size_E"];
            my.Cells[9, 5].Value  = dr["Batch_E"];
            my.Cells[10, 5].Value = Convert.ToDateTime(dr["Mfg_E"]).ToString("yyyy/MM/dd");
            my.Cells[11, 5].Value = Convert.ToDateTime(dr["Expiry_E"]).ToString("yyyy/MM/dd");
            my.Cells[12, 5].Value = dr["Quantity_E"];
            my.Cells[13, 5].Value = dr["Pack_E"];
            my.Cells[15, 6].Value = dr["CFDA_E"];
            my.Cells[16, 6].Value = dr["Gross_E"];
            my.Cells[17, 6].Value = dr["Carton_E"];

            my = wb.Worksheets[Convert.ToInt32(dr["标签类型"]) + 1];
            my.Select();
            oXL.Visible = true;
            try
            {
                my.PrintOut(); // oXL.Visible=false 就会直接打印该Sheet
            }
            catch
            {
            }

            wb.Close(false);
            oXL.Quit();
            Marshal.ReleaseComObject(wb);
            Marshal.ReleaseComObject(oXL);
            wb  = null;
            oXL = null;
        }
Ejemplo n.º 7
0
        public static void printLable(int id)
        {
            String sql = "select * from 标签 where ID={0}";

            System.Data.DataTable dt = new System.Data.DataTable();
            if (!mySystem.Parameter.isSqlOk)
            {
                OleDbDataAdapter    da = new OleDbDataAdapter(String.Format(sql, id), mySystem.Parameter.connOle);
                OleDbCommandBuilder cb = new OleDbCommandBuilder(da);

                da.Fill(dt);
            }
            else
            {
                SqlDataAdapter    da = new SqlDataAdapter(String.Format(sql, id), mySystem.Parameter.conn);
                SqlCommandBuilder cb = new SqlCommandBuilder(da);

                da.Fill(dt);
            }

            if (dt.Rows.Count == 0)
            {
                MessageBox.Show("无法找到标签信息");
                return;
            }
            DataRow dr   = dt.Rows[0];
            string  path = Directory.GetCurrentDirectory();

            Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel._Workbook   wb  = null;
            wb = oXL.Workbooks.Open(path + @"/../../xls/cleancut/7 标签-清洁分切.xlsx");
            _Worksheet my = wb.Worksheets[wb.Worksheets.Count];

            //dr["生产指令"] = mySystem.Parameter.cleancutInstruction;
            //dr["生产指令ID"] = mySystem.Parameter.cleancutInstruID;
            //dr["膜代码"] = cb膜代码.Text;
            //dr["批号-卷号 "] = tb批号.Text;
            //dr["合格数量米"] = tb米.Text;
            //dr["合格数量千克"] = tbKg.Text;
            //dr["原膜代码"] = cb原膜代码.Text;
            //dr["分切日期"] = dtp分切日期.Value.ToString("yyyy/MM/dd");
            //dr["分切班次"] = cb白班.Checked ? "白班" : "夜班";

            my.Select();
            my.Cells[2, 2].Value = dr["膜代码"];
            my.Cells[3, 2].Value = dr["批号_卷号"];
            my.Cells[4, 2].Value = dr["合格数量米"] + "米;  " + dr["合格数量千克"] + "Kg";
            my.Cells[5, 2].Value = dr["原膜代码"];
            my.Cells[6, 2].Value = String.Format("{0} {1}", Convert.ToDateTime(dr["分切日期"]).ToString("yyyy/MM/dd"),
                                                 dr["分切班次"].ToString() == "白班" ? "白班☑ 夜班□" : "白班□ 夜班☑");

            my = wb.Worksheets[1];
            my.Select();
            oXL.Visible = false;
            my.PrintOut();
            // 关闭文件,false表示不保存
            wb.Close(false);
            // 关闭Excel进程
            oXL.Quit();
            // 释放COM资源
            Marshal.ReleaseComObject(wb);
            Marshal.ReleaseComObject(oXL);
            wb  = null;
            oXL = null;
        }