Пример #1
0
        /// <summary>
        /// 异或
        /// </summary>
        /// <param name="aHex"></param>
        /// <param name="bHex"></param>
        /// <returns></returns>
        public static string AXorB(string aHex, string bHex)
        {
            string ret;
            long   retDec, aDec, bDec;

            //16转10
            aDec = Convert.ToInt64(aHex, 16);

            //16转10
            bDec = Convert.ToInt64(bHex, 16);

            retDec = aDec ^ bDec;
            ret    = PubFunc.DecToHex(retDec);

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// 将DataGridView中的数据,从起始列开始,原样导出到EXCEL中
        /// </summary>
        /// <param name="mView">源DataGridView</param>
        /// <param name="startIndex">起始列序号</param>
        /// <returns>0-成功,1-失败</returns>
        static public int Deport(System.Windows.Forms.DataGridView mView, int startIndex)
        {
            try
            {
                IWorkbook  mWorkbook  = new NPOI.HSSF.UserModel.HSSFWorkbook();
                ISheet     mSheet     = mWorkbook.CreateSheet("Sheet1");
                ICellStyle styleRight = mWorkbook.CreateCellStyle();
                //ICellStyle NumberStyle = mWorkbook.CreateCellStyle();
                //IDataFormat format = mWorkbook.CreateDataFormat();
                styleRight.Alignment         = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
                styleRight.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.CENTER;
                //NumberStyle.DataFormat = format.GetFormat("0.00");
                ICell mCell;
                int   i, j;
                int   x = 0;
                //DataGridView mView = dgvReport;

                //添加标头
                IRow mRow = mSheet.CreateRow(0);
                for (i = startIndex; i <= mView.Columns.Count - 1; i++)
                {
                    if (mView.Columns[i].Visible == true)
                    {
                        mCell = mRow.CreateCell(x);
                        x++;
                        mCell.SetCellValue(mView.Columns[i].HeaderText);
                        mCell.CellStyle = styleRight;
                    }
                }
                //添加内容

                for (i = 1; i <= mView.RowCount; i++)
                {
                    mRow = mSheet.CreateRow(i);
                    x    = 0;
                    for (j = startIndex; j <= mView.Columns.Count - 1; j++)
                    {
                        if (mView.Columns[j].Visible == true)
                        {
                            mCell = mRow.CreateCell(x);
                            x++;
                            if (PubFunc.IsNumber(Convert.ToString(mView.Rows[i - 1].Cells[j].Value)) == true)
                            {
                                mCell.SetCellValue(Convert.ToDouble(mView.Rows[i - 1].Cells[j].Value));
                            }
                            else
                            {
                                mCell.SetCellValue(Convert.ToString(mView.Rows[i - 1].Cells[j].Value));
                            }
                            mCell.CellStyle = styleRight;
                        }
                    }
                }



                //创建文件
                SaveFileDialog mDialog = new SaveFileDialog();
                mDialog.AddExtension     = true;
                mDialog.DefaultExt       = "xls";
                mDialog.Filter           = "Excel Worksheets(*.xls)|*.xls";
                mDialog.InitialDirectory = System.Environment.CurrentDirectory;
                mDialog.FileName         = "导出数据-" + DateTime.Now.ToString("yyyyMMddhhmmss");
                if (mDialog.ShowDialog() == DialogResult.OK)
                {
                    Stream mFile = mDialog.OpenFile();
                    mWorkbook.Write(mFile);
                    mFile.Close();
                    MessageBox.Show("保存成功!", "提示");
                    return(0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            return(1);
        }