Exemplo n.º 1
0
 /// <summary>
 /// 仅仅加载显示xlsx
 /// </summary>
 private void OnlyLoadXlsx()
 {
     viewModel.BusyWindowVisibility = Visibility.Visible;
     System.Threading.ThreadStart start = delegate()
     {
         System.Threading.Thread.Sleep(20);
         try
         {
             viewModel.PicGridVisibility            = Visibility.Collapsed;
             viewModel.AxFramerControlVisibility    = Visibility.Collapsed;
             viewModel.SpreadsheetControlVisibility = Visibility.Visible;
             Task task = Task.Run(() =>
             {
                 Dispatcher.BeginInvoke(new Action(() =>
                 {
                     DevExpress.Spreadsheet.IWorkbook workbook = spreadsheetControl1.Document;
                     workbook.Options.Culture = new System.Globalization.CultureInfo("en-US");
                     workbook.LoadDocument(viewModel.CurrentMyFolderData.FilePath);
                 }));
             });
         }
         catch (Exception ex)
         {
             Dispatcher.Invoke(new Action(() => {
                 viewModel.BusyWindowVisibility = Visibility.Collapsed;
             }));
         }
     };
     System.Threading.Thread t = new System.Threading.Thread(start);
     t.IsBackground = true;
     t.Start();
 }
Exemplo n.º 2
0
 public String getSheetName(int index)
 {
     DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
     if (workbook.Worksheets.Count >= index)
     {
         return(workbook.Worksheets[index - 1].Name);
     }
     return(null);
 }
Exemplo n.º 3
0
 private void layout2_Load(object sender, EventArgs e)
 {
     Ex = this.layout2;
     workbook = Ex.SpreadsheetControl1.Document;
     Ex.Execute_Click += (o,ev) =>
     {
         int check = 0;
         var Data = (Excel.GetTableFromExcel(Ex.SpreadsheetControl1)).AsEnumerable();
         List<thoikhoabieu> list = new List<thoikhoabieu>();
         try
         {
             list = (from s in Data
                     select new thoikhoabieu
                     {
                         maca = s.Field<String>("maca"),
                         magv = s.Field<String>("magv"),
                         mahp = s.Field<String>("mahp"),
                         malop = s.Field<String>("malop"),
                         manganh = s.Field<String>("manganh"),
                         siso = Convert.ToInt32(s["siso"]),
                         tuanhocbatdau = Convert.ToInt32(s["tuanhocbatdau"]),
                         tuanhocketthuc = Convert.ToInt32(s["tuanhocketthuc"]),
                     }).ToList();
             if (list.Count > 0)
             {
                 foreach (thoikhoabieu ob in list)
                 {
                     check = (new ClassRoomBUS.ThoikhoabieuBUS()).Insert(ob);
                     if (check == 0)
                     {
                         DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có dữ liệu nào trong Bảng");
                         return;
                     }
                 }
             }
             else
             {
                 DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có dữ liệu nào trong Bảng");
                 return;
             }
         }
         catch (Exception ex)
         {
             var k = ex.Message;
         }
         //for (int i = 0; i < table.Rows.Count;i++ )
         //{
         //    DataRow row = table.Rows[i];
         //    for(int j = 0; j < table.Columns.Count;j++)
         //    {
         //        System.Diagnostics.Debug.Write(row[j].ToString());
         //    }
         //}
         DevExpress.XtraEditors.XtraMessageBox.Show("Đã Cập nhật vào Cơ Sở Dữ Liệu");
     };
 }
Exemplo n.º 4
0
        public List <Sheet> getAllExcelSheets()
        {
            List <Sheet> Sheets = new List <Sheet>(0);

            DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
            foreach (DevExpress.Spreadsheet.Worksheet worksheet in workbook.Worksheets)
            {
                Sheets.Add(new Sheet(worksheet.Index + 1, worksheet.Name));
            }
            return(Sheets);
        }
Exemplo n.º 5
0
        public List <String> getSheetNames()
        {
            List <String> names = new List <String>(0);

            DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
            foreach (DevExpress.Spreadsheet.Worksheet worksheet in workbook.Worksheets)
            {
                names.Add(worksheet.Name);
            }
            return(names);
        }
Exemplo n.º 6
0
 public void Protect(bool protect)
 {
     DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
     if (!workbook.IsProtected && protect)
     {
         workbook.Protect("Password", true, true);
     }
     else
     {
         workbook.Unprotect("Password");
     }
 }
Exemplo n.º 7
0
 protected DevExpress.Spreadsheet.Worksheet getWorksheet(string sheetName)
 {
     DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
     foreach (DevExpress.Spreadsheet.Worksheet worksheet in workbook.Worksheets)
     {
         if (worksheet.Name.Equals(sheetName))
         {
             return(worksheet);
         }
     }
     return(null);
 }
Exemplo n.º 8
0
        private void DisplayTemplateExcelFile()
        {
            if (string.IsNullOrEmpty(_templateFilePath))
            {
                return;
            }

            if (System.IO.File.Exists(_templateFilePath))
            {
                DevExpress.Spreadsheet.IWorkbook workbook = spreadsheetControl1.Document;
                workbook.LoadDocument(_templateFilePath);
            }
        }
Exemplo n.º 9
0
 private void SpreadsheetControl1_DocumentLoaded(object sender, EventArgs e)
 {
     System.Windows.Threading.Dispatcher x     = System.Windows.Threading.Dispatcher.CurrentDispatcher;
     System.Threading.ThreadStart        start = delegate()
     {
         System.Threading.Thread.Sleep(500);
         Dispatcher.Invoke(new Action(() => {
             try
             {
                 DevExpress.Spreadsheet.IWorkbook workbook = spreadsheetControl1.Document;
                 int sheetCount = workbook.Worksheets.Count;
                 foreach (var searchStr in viewModel.CurrentMyFolderData.UnChekedWordInfos.Select(y => y.Name).ToList())
                 {
                     for (int k = 0; k < sheetCount; k++)
                     {
                         var worksheet = workbook.Worksheets[k];
                         IEnumerable <DevExpress.Spreadsheet.Cell> searchResult = worksheet.Search(searchStr);
                         foreach (DevExpress.Spreadsheet.Cell cell in searchResult)
                         {
                             string str = cell.DisplayText;
                             cell.Fill.BackgroundColor = System.Drawing.ColorTranslator.FromHtml("#ffff00");
                             MatchCollection mc        = Regex.Matches(cell.DisplayText, searchStr, RegexOptions.IgnoreCase);
                             if (mc.Count > 0)
                             {
                                 foreach (System.Text.RegularExpressions.Match m in mc)
                                 {
                                     //赋值range
                                     var itemDetailInfo = viewModel.CurrentMyFolderData.UnChekedWordInfos.FirstOrDefault(y => y.Name == searchStr).UnChekedWordInLineDetailInfos.Where(z => z.TypeTextFrom == "Text" && z.XlsxHasValue == false).FirstOrDefault();
                                     if (itemDetailInfo != null)
                                     {
                                         itemDetailInfo.WorkSheetIndex = k;
                                         itemDetailInfo.Cell           = cell;
                                         itemDetailInfo.XlsxHasValue   = true;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             catch (Exception ex)
             { }
             viewModel.BusyWindowVisibility = Visibility.Collapsed;
         }));
     };
     System.Threading.Thread t = new System.Threading.Thread(start);
     t.IsBackground = true;
     t.Start();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Sauve le fichier ouvert sous un autre nom.
 /// </summary>
 /// <param name="filePath">L'url du nouveau fichier</param>
 /// <param name="overwrite"></param>
 /// <returns>
 /// OperationState.CONTINUE si l'opération a réussi
 /// OperationState.STOP sinon
 /// </returns>
 public OperationState SaveAs(String filePath, bool overwrite)
 {
     try
     {
         DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
         using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
         {
             workbook.SaveDocument(stream, DevExpress.Spreadsheet.DocumentFormat.Xlsx);
         }
         return(OperationState.CONTINUE);
     }
     catch (Exception)
     {
         return(OperationState.STOP);
     }
 }
Exemplo n.º 11
0
 /// <summary>
 /// Ouvre le fichier dont l'url est passé en paramètre.
 /// </summary>
 /// <param name="filePath">L'url du fichier à ouvrir</param>
 /// <param name="progID">Le type de fichier à ouvrir</param>
 /// <returns>
 /// OperationState.CONTINUE si l'opération a réussi
 /// OperationState.STOP sinon
 /// </returns>
 public OperationState Open(string filePath)
 {
     try
     {
         ThrowEvent = false;
         DevExpress.Spreadsheet.IWorkbook workbook = this.spreadsheetControl.Document;
         using (FileStream stream = new FileStream(filePath, FileMode.Open))
         {
             workbook.LoadDocument(stream, DevExpress.Spreadsheet.DocumentFormat.Xlsx);
             this.spreadsheetControl.Options.Save.CurrentFileName = filePath;
         }
         ThrowEvent = true;
         return(OperationState.CONTINUE);
     }
     catch (Exception)
     {
         ThrowEvent = true;
         return(OperationState.STOP);
     }
 }