Új hozzászólás Aktív témák
-
ubid
senior tag
válasz
sztanozs #3713 üzenetére
nem.
A kód a következő :
BTN eseménye :
private void ImportBtnClick(object sender, RoutedEventArgs e)
{
if (AutomationFactory.IsAvailable)
{
if (InitializeExcel())
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel workbook (*.xls;*.xlsx;*.xlsm)|*.xls;*.xlsx;*.xlsm|All files|*.*";
openFileDialog.ShowDialog();
FileInfo fileInfo = openFileDialog.File;
if (fileInfo != null)
{
tbMessages.Text = "The processing may take several minutes. Please wait...\n";
btnImporter.IsEnabled = false;
DoBackGroundWork(fileInfo);
}
}
else
{
MessageBox.Show("Excel is not available.");
}
}
else
{
MessageBox.Show("Automation is not available.");
}
}Ez hívja ugye a DoBackGroundWork -öt :
public FileInfo fileNameProperty { get; set; }
private void DoBackGroundWork(FileInfo f)
{
BackgroundWorker worker = new BackgroundWorker();
fileNameProperty = f;
worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.RunWorkerAsync(fileNameProperty);
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
btnImporter.IsEnabled = true;
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
int totalSteps = 30;
FileInfo file = e.Argument as FileInfo;
ProcessExcelSheet(file);
for (int i = 1; i <= totalSteps; i++)
{
///.......
}
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}És ugye a ProcessExcelSheet dolgozik sokáig...
Az pedig így néz ki :private void ProcessExcelSheet(FileInfo File)
{
Object missingValue = System.Reflection.Missing.Value;
bool errorHappened = false;
dynamic workbook = excel.Workbooks.Open(File.FullName);
try
{
...............
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- Megaport gaming pc + billentyű
- Csere-Beszámítás! Ryzen 9 9950X3D Processzor! 16Mag-32Szál!
- Csere-Beszámítás! Intel Core I9 14900KS 24Mag-32Szál processzor!
- Csere-Beszámítás! Asus Rog Strix GTX 1080Ti 11GB GDDR5X Videokártya!
- Csere-Beszámítás! Asrock Challanger B580 12GB GDDR6 Videokártya! Bemutató Darab!
- BESZÁMÍTÁS! Microsoft XBOX Series S 512GB játékkonzol garanciával hibátlan működéssel
- Targus Universal USB 3.0 DV1K-2K Compact docking station (DisplayLink)
- BESZÁMÍTÁS! Intel Core i9 14900KF 24 mag 32 szál processzor garanciával hibátlan működéssel
- Lenovo ThinkCentre M720s SFF / M920T tower -Számla, garancia, WIN11
- LG 25GR75FG - E-Sport Monitor - FHD 360Hz 1ms - NVIDIA Reflex + G-sync - AMD FreeSync - HDR 400
Állásajánlatok
Cég: PC Trade Systems Kft.
Város: Szeged
Cég: CAMERA-PRO Hungary Kft
Város: Budapest