C# de çok yeni ve oldukça karışık bir kod yazdım. İnternette çok fazla kurs yapıyorum ve bir çok problemlere yaklaşmanın çeşitli yolları olduğunu söyleyebilirim. Şimdi bir .Doc Word dosyasını yükleyecek ve ifadeler kullanarak ilgili bilgileri arayacak bir program yaptık.Word Interop işleme nasıl hızlandırılır?
Şimdi benim çözümümdeki benim problemim bu programın FOREVER almasıdır! Aşağıdaki kodu tamamlamak için 30Mins - 1Hour hakkında konuşuyorum.
Benim küçük programımı biraz daha az nasıl temizleyeceğime dair herhangi bir fikir var mı? İnşallah bu çözümlerin bilgimi önemli ölçüde arttıracağını umuyorum ki şimdiden teşekkürler!
Saygılarımızla chris
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int id = 0;
public int[] iD = new int[100];
public string[] timeOn = new string[100];
public string[] timeOff = new string[100];
public string[] dutyNo = new string[100];
public string[] day = new string[100];
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document document = application.Documents.Open("c:\\Users\\Alien\\Desktop\\TESTJOBS.doc");
//the following for will loop for all words
int count = document.Words.Count;
for (int i = 1; i <= count; i++)
{
// the following if statement will look for the first word that is On
// this is then (on the file) proceded by 04:00 (thus i+2/3/4 respectively)
if (document.Words[i].Text == "On")
{
iD[id] = id;
// Console.WriteLine("ID Number ={0}", iD[id]);
dutyNo[id] = document.Words[i - 14].Text;
// Console.WriteLine("duty No set to:{0}", dutyNo[id]);
timeOn[id] = document.Words[i + 2].Text + document.Words[i + 3].Text + document.Words[i + 4].Text;
// Console.WriteLine("on time set to:{0}", timeOn[id]);
// the following if (runs if the last word was not "On" and then searches for the word "Off" which procedes "On" in the file format)
// this is then (on the file) proceded by 04:00 (thus i+2/3/4 respectively)
}
else if (document.Words[i].Text == "Off")
{
timeOff[id] = document.Words[i + 2].Text + document.Words[i + 3].Text + document.Words[i + 4].Text;
//Console.WriteLine("off time set to:{0}", timeOff[id]);
// the following if (runs if the last word was not "Off" and then searches for the word "Duty" which procedes "Off" in the file format)
// this is then (on the file) proceded by 04:00 (thus i+2/3/4 respectively)
}
else if (document.Words[i].Text == "Days" && !(document.Words[i + 3].Text == "Type"))
{
day[id] = document.Words[i + 2].Text;
//Console.WriteLine("day set to:{0}", day[id]);
//we then print the whole new duty out to ListBox1
listBox1.Items.Add(string.Format("new duty ID:{0} Time on:{1} Time off:{2} Duty No:{3} Day:{4}", iD[id], timeOn[id], timeOff[id], dutyNo[id], day[id]));
id++;
}
}
for (int i = 1; i <= 99; i++)
{
Console.WriteLine("new duty ID:{0} Time on:{1} Time off:{2} Duty No:{3} Day:{4}", iD[id], timeOn[id], timeOff[id], dutyNo[id], day[id]);
}
}
}
}
: \\ Users \ \ Alien \\ Desktop \\ TESTJOBS.doc "_) –
haha onlar bana sadece onları ışınladı! –
Zamanın ne olduğunu görmek için zamanlama teşhislerini (Kronometre sınıfı) koda koydunuz mu? – ChrisF