åå°ï¼
<div style="text-align:center;">
ä¸ä¼ è¯é¢æå±ç±»åï¼
<asp:DropDownList ID="ddlques_type" runat="server" Height="23px" Width="148px">
</asp:DropDownList><br/>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnShangChuan" runat="server" Text="å¼å§ä¸ä¼ Wordæ°æ®"
onclick="btnShangChuan_Click" Width="131px"/>
<asp:Label ID="lblText" runat="server" Text="*" ForeColor="#FF3300"></asp:Label>
注æï¼ä¸ä¼ æ件åç¼å为.docæ.docxçWordæ件
</div>
åå°ï¼
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Word;
if (this.FileUpload1.FileName.Trim() == "")
{
this.lblText.Text = "请éæ©è¦ä¸ä¼ Wordæ件ï¼";
return;
}
//çéåæ³æ件
string fileName = this.FileUpload1.FileName;
string fileType = ".doc,.docx";
int dian = fileName.LastIndexOf('.');
string exten = fileName.Substring(dian);//å¾å°åç¼å
int IsHas = fileType.IndexOf(exten);//æ ¹æ®åç¼åæ¥æ¾å¯¹æ¯
if (IsHas == -1)//没ææ¾å°å¯¹åºçåç¼å称æ¶
{
this.lblText.Text = "ä¸å
许ä¸ä¼ éæ³å¾çï¼";
this.FileUpload1.Focus();
return;
}
else
{
object oMissing = System.Reflection.Missing.Value;
//æå¼ææ¡£
Microsoft.Office.Interop.Word._Application oWord = null;
Microsoft.Office.Interop.Word._Document oDoc = null;//è®°å½wordæå¼çææ¡£
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false;
//å¾å°ç»å¯¹çè·¯å¾
//string path = this.FileUpload1.PostedFile.FileName;//IEé®é¢ï¼ç°åªæIE6è½å¾å°å
¨è·¯å¾
object path = @"E:\" + FileUpload1.FileName; //ææ¶åçæ»è·¯å¾
//æå¼ææ¡£
oDoc = oWord.Documents.Open(ref path,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
object unknow = Type.Missing;
object saveChanges = Microsoft.Office.Interop.Word.WdSaveOptions.wdPromptToSaveChanges;
OnlineExam exam = null;
List<OnlineExam> list = new List<OnlineExam>();
for (int i = 1; i < oDoc.Paragraphs.Count; i++)
{
if (i == 1 || i % 6 == 1)//é¢ç®
{
exam = new OnlineExam();
exam.Content = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim());
}
if (i == 2 || i % 6 == 2)//çæ¡A
{
exam.Ques_key_a = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim().Replace("A.",""));
}
if (i == 3 || i % 6 == 3)//çæ¡B
{
exam.Ques_key_b = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim().Replace("B.", ""));
}
if (i == 4 || i % 6 == 4)//çæ¡C
{
exam.Ques_key_c = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim().Replace("C.", ""));
}
if (i == 5 || i % 6 == 5)//çæ¡D
{
exam.Ques_key_d = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim().Replace("D.", ""));
}
if (i == 6 || i % 6 == 0)//æ£ç¡®çæ¡
{
string correctKey = Convert.ToString(oDoc.Paragraphs[i].Range.Text.Trim());
int indexof = correctKey.IndexOf("ï¼");
if (indexof < 0)
{
//å
³éwordææ¡£
oWord.ActiveDocument.Close(ref saveChanges, ref unknow, ref unknow);
//å
³éwordç¨åº
oWord.Quit(ref saveChanges, ref unknow, ref unknow);
this.lblText.Text = "第" + i/6 + "é¢éè¿ï¼è¯é¢ææ¡£æ åæ ¼å¼æ误ï¼è¯·æ£æ¥ï¼";
return;
}
string correctKey2 = correctKey.Substring(indexof + 1, correctKey.Length - (indexof + 1));
exam.Ques_correctKey = correctKey2;
if (correctKey2.Split(',').Length > 1)
{
exam.Ques_check_type = 1;//å¤é
}
else
{
exam.Ques_check_type = 0;//åé
}
list.Add(exam);
}
}
if (list.Count > 0)
{
questions_info questions = null;
for (int i = 0; i < list.Count; i++)
{
questions = new questions_info();
questions.ques_typeId = Convert.ToInt32(ddlques_type.SelectedValue);
questions.ques_check_type = Convert.ToInt32(list[i].Ques_check_type);
questions.ques_registTime = DateTime.Now;
questions.content = list[i].Content;
questions.ques_key_a = list[i].Ques_key_a;
questions.ques_key_b = list[i].Ques_key_b;
questions.ques_key_c = list[i].Ques_key_c;
questions.ques_key_d = list[i].Ques_key_d;
questions.ques_correctKey = list[i].Ques_correctKey;
examManageBll.InsertIntoQuestions(questions);
}
this.lblText.Text = "ä¸ä¼ æåï¼";
}
if (list.Count == 0)
{
this.lblText.Text = "ææ¡£æ ¼å¼æ åæ误ï¼è¯·æ£æ¥ï¼";
}
//å
³éwordææ¡£
oWord.ActiveDocument.Close(ref saveChanges, ref unknow, ref unknow);
//å
³éwordç¨åº
oWord.Quit(ref saveChanges, ref unknow, ref unknow);
}
//ææ¡£æ¯ä¸è¡ä¸è¡è¯»çï¼ä¸æ¸
æ¥è¿æ没ææ´å¥½çæ¹æ³
温馨提示:答案为网友推荐,仅供参考