从c#windows应用程序导出到带有文本颜色的单词 [英] export to word with text color from c# windows application
问题描述
您好我想从c#windows应用程序导出到ms文本和图像两者都在doc文件中并通过c#编码更改文本颜色....通过此编码导出到word但不在文件和图像文件中不改变颜色PLZ帮帮我..
提前感谢...........
我的邮箱是: - vivek.1370@gmail.com
和第二个: - vivekpalmailbox@gmail.com
private void ExportToWord()
{
int s1;
for(s1 = 0; s1< 3; s1 ++)
{
string strForPrint =;
//第一个学生详细信息
strForPrint + =SJS PUBLIC SCHOOL+\ n;
strForPrint + =基于CBSE的英语中等男女同校课程+\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n;
pi c_logo_sjs.Image.Save(E:\\ myimage\\myimage.jpg,System.Drawing.Imaging.ImageFormat.Jpeg);
Word.Application wordApp = new Word。 Application();
wordApp.Visible = false;
Word.Document doc = wordApp.Documents.Add();
doc.InlineShapes .AddPicture(E:\\ myimage \\ myimage.doc);
// strForPrint + = richTextBox1.Text +\\\\ n;
strForPrint + =REPORT BOOK+\ n;
strForPrint + =会议2014-2015+\ n \ n;
strForPrint + =学生姓名:+ txt_stu_name.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\\卷号:+ txt_roll.Text +\ n \ n;
strForPrint + =Class:+ txt_class.Text +\t;
strForPr int + =Section:+ txt_section.Text +\t;
strForPrint + =Scholar No:+ txt_scholar.Text +\\\\\\\\\ \\ n \\\ n \\ n;
strForPrint + =出生日期:+ txt_dob.Text +\\\\\\\\\\\\\\ n;
strForPrint + =母亲的名字:+ txt_mother.Text +\\\\\\\\\ n;
strForPrint + =父亲的名字:+ txt_father.Text +\\\\\\\\\ n;
strForPrint + =地址:+ txt_address.Text +\\\\\\\\\\\\\\\\\\\\\\\\\ =撕这边行--------------------------------------------- --------------+\\\\ n;
//第二个学生详细信息
strForPrint + =SJS公立学校+\ n;
strForPrint + =基于C.B.S.E的英语中等公立学校课程+\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n \\ n;
strForPrint + =报告书+\ n;
strForPrint + =Session 2014-2015+\ n \ n;
strForPrint + =学生姓名:+ txt_name1.Text +\ t \\\ t;
strForPrint + =Roll No:+ txt_roll1.Text +\\\\\\\ n;
strForPrint + = Class:+ txt_class1.Text +\\\;
strForPrint + =Section:+ txt_section1.Text +\\\;
strForPrint + =学者号:+ txt_scholar1.Text +\\\\\\\\\ n;
strForPrint + = 出生日期:+ txt_dob1.Text +\\\\\\\\\ n;
strForPrint + =母亲姓名:+ txt_mother1 .Text +\\\\\\\\\ \\ n;
strForPrint + =父亲的名字:+ txt_father1.Text +\\\\\\\\\\ n;
strForPrint + =地址:+ txt_address1.Text +\\\\ n;
//第一个学生分数< br $> b $ b
strForPrint + = Exam_I_Term.Text +\ n \ n;
strForPrint + =\\\\\\\ \\+ label1.Text +\ n \ n;
strForPrint + = lbl_sub.Text +\\\+ lbl_english.Text +\\ \\ r \+ lbl_evs.Text +\\\+ lbl_hindi.Text +\\\+ lbl_math.Text +\\\+ lbl_total_marks.Text + \\\\\ n;
strForPrint + = lbl_marks.Text +\\\\\\+ lbl_fa_1_english.Text +\ r \ t \\\+ lbl_fa_1_evs.Text +\\\\\\\\+ lbl_fa_1_hindi.Text +\\\\\\\\ + lbl_fa_1_math.Text +\\\\\\+ lbl_fa_1_total.Text +\\\\\\\\\\\
strForPrint + = lbl_grade.Text +\\\\\\\\\\\\\\\\\\\\\\\\\ r \\\\\\\\\\\+ lbl_fa_1_grade.Text +\\\\ n;
strForPrint + = lbl_attendance.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\\\ r \\\\\\+ lbl_fa_1_attendance.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;
strForPrint + = lbl_teacher_signature.Text +\\\ \t+ lbl_principal_signa ture.Text +\\\\\\\ n;
strForPrint + =\\\\\\\\\\\\\\\ \\ r \+ lbl_grading_norm_index.Text +\\\\ n;
strForPrint + = lbl_A_outstainding.Text ++ lbl_B_Excellent.Text ++ lbl_C_very_good。文字+\\\\\\\ n;
strForPrint + = lbl_D_good.Text +\\\\\\\\\\\\ + label3.Text +\\\\\\\\\\\\\\\\\\\\\\\\ /第二个学生标记
strForPrint + = Exam_I_Term1.Text +\ nn \ n;
strForPrint + =\\\\\\\\ \\ t+ label1_1.Text +\ n \ n;
strForPrint + = lbl_sub1.Text +\\\+ lbl_english1.Text +\\\\ \\ t+ lbl_evs1.Text +\\\+ lbl_hindi1.Text +\\\+ lbl_math1.Text +\\\+ lbl _total_marks1.Text +\\\\\\\ n;
strForPrint + = lbl_marks1.Text +\\\\\\+ lbl_fa_1_english1.Text + \\\\\\\+ lbl_fa_1_evs1.Text +\\\\\\\\+ lbl_fa_1_hindi1.Text +\\\\\\\\\\\ t+ lbl_fa_1_math1.Text +\\\\\\\\+ lbl_fa_1_total1.Text +\\\\\\\\\\ >
strForPrint + = lbl_grade1.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\ + + + lbl_fa_1_grade1.Text +\\\\ n;
strForPrint + = lbl_attendance1.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\+ lbl_fa_1_attendance1.Text +\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
strForPrint + = lbl_teacher_signature1.Text +\\\\\\\\\\\\\\\\\\\\\\ \\ t+ lbl_principal_signature1.Text +\\\\\\\ n;
strForPrint + =\\\\\\\\\ \ t \\\+ lbl_grading_norm_index1.Text +\\\\ n;
strForPrint + = lbl_A_outstainding1.Text +\\\+ lbl_B_Excellent1.Text +\\\+ lbl_C_very_good1.Text +\\\\\\\ n;
strForPrint + = lbl_D_good1.Text +\ r \\\\\\\\\+ label3.Text +\\\\ n;
label2.Text =hello .......;
label2.ForeColor = Color.Green;
编码utf 16 = Encoding.GetEncoding(1254);
byte [] output = utf16.GetBytes(strForPrint);
FileStream fs = new FileStream(sfd.FileName,FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(output,0,output.Length); //将数据写入文件
bw.Flush();
bw.Close();
fs.Close();
}
}
private void button1_Click(object sender,EventArgs e)
{
sfd.Filter =Word Documents(* .doc)| * .doc;
if (sfd.ShowDialog()== DialogResult.OK)
{
ExportToWord();
< br $>
}
}
hi i want to export from c# windows application to ms word text and image both in a doc file and change text color through c# coding.... through this coding export to word but not in a file both text and image and not change color plz help me ..
thanks in advance...........
my email is:- vivek.1370@gmail.com
and second is:- vivekpalmailbox@gmail.com
private void ExportToWord()
{
int s1;
for(s1=0;s1<3;s1++)
{
string strForPrint = "";
//first student detail
strForPrint += " S.J.S. PUBLIC SCHOOL" + "\n";
strForPrint += "An English Medium Co-educational School Based on C.B.S.E. Curriculum" + "\n\n\n\n\n";
pic_logo_sjs.Image.Save("E:\\myimage\\myimage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
Word.Application wordApp = new Word.Application();
wordApp.Visible = false;
Word.Document doc = wordApp.Documents.Add();
doc.InlineShapes.AddPicture("E:\\myimage\\myimage.doc");
// strForPrint += richTextBox1.Text + "\r\n";
strForPrint += " REPORT BOOK" + "\n";
strForPrint += " Session 2014-2015" + "\n\n";
strForPrint += "Student Name : " + txt_stu_name.Text + "\r\t\r\t\r\t";
strForPrint += "Roll No : " + txt_roll.Text + "\n\n";
strForPrint += "Class : " + txt_class.Text + "\t";
strForPrint += "Section : " + txt_section.Text + "\t";
strForPrint += "Scholar No : " + txt_scholar.Text + "\r\n\r\n\r\n";
strForPrint += "Date Of Birth : " + txt_dob.Text + "\r\n\r\n\r\n";
strForPrint += "Mother's Name : " + txt_mother.Text + "\r\n\r\n\r\n";
strForPrint += "Father's Name : " + txt_father.Text + "\r\n\r\n\r\n";
strForPrint += "Address : " + txt_address.Text + "\r\n\r\n\r\n\n\n\n\n";
strForPrint += "Tear here line-----------------------------------------------------------" + "\r\n";
//second student detail
strForPrint += " S.J.S. PUBLIC SCHOOL" + "\n";
strForPrint += "An English Medium Co-educational School Based on C.B.S.E. Curriculum" + "\n\n\n\n\n";
strForPrint += " REPORT BOOK" + "\n";
strForPrint += " Session 2014-2015" + "\n\n";
strForPrint += "Student Name : " + txt_name1.Text + "\t\t\t";
strForPrint += "Roll No : " + txt_roll1.Text + "\r\n\r\n";
strForPrint += "Class : " + txt_class1.Text + "\r\t";
strForPrint += "Section : " + txt_section1.Text + "\r\t";
strForPrint += "Scholar No : " + txt_scholar1.Text + "\r\n\r\n\r\n";
strForPrint += "Date Of Birth : " + txt_dob1.Text + "\r\n\r\n\r\n";
strForPrint += "Mother's Name : " + txt_mother1.Text + "\r\n\r\n\r\n";
strForPrint += "Father's Name : " + txt_father1.Text + "\r\n\r\n\r\n";
strForPrint += "Address : " + txt_address1.Text + "\r\n\n";
//First student marks
strForPrint += Exam_I_Term.Text + "\n\n";
strForPrint += "\r\t\r\t" + label1.Text + "\n\n";
strForPrint += lbl_sub.Text + "\r\t" + lbl_english.Text + "\r\t" + lbl_evs.Text + "\r\t" + lbl_hindi.Text + "\r\t" + lbl_math.Text + "\r\t" + lbl_total_marks.Text + "\r\t\n\n";
strForPrint += lbl_marks.Text + "\r\t\r" + lbl_fa_1_english.Text + "\r\t\r\t" + lbl_fa_1_evs.Text + "\r\t\r\t" + lbl_fa_1_hindi.Text + "\r\t\r\t" + lbl_fa_1_math.Text + "\r\t\r\t" + lbl_fa_1_total.Text + "\r\t\r\t\n\n";
strForPrint += lbl_grade.Text + "\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_fa_1_grade.Text + "\r\n\n";
strForPrint += lbl_attendance.Text + "\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_fa_1_attendance.Text + "\r\n\n\n\n";
strForPrint += lbl_dash_teacher.Text + "\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_dash_principal.Text + "\r\n";
strForPrint += lbl_teacher_signature.Text + "\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_principal_signature.Text + "\r\n\n\n";
strForPrint += "\r\t\r\t\r\t\r\t" + lbl_grading_norm_index.Text + "\r\n\n";
strForPrint += lbl_A_outstainding.Text + "" + lbl_B_Excellent.Text + "" + lbl_C_very_good.Text+ "\r\n\r\n";
strForPrint += lbl_D_good.Text + "\r\t\r\t\r\t" + label3.Text + "\r\n\n\n\n\n\n\n";
//second student marks
strForPrint += Exam_I_Term1.Text + "\n\n";
strForPrint += "\r\t\r\t" + label1_1.Text + "\n\n";
strForPrint += lbl_sub1.Text + "\r\t" + lbl_english1.Text + "\r\t" + lbl_evs1.Text + "\r\t" + lbl_hindi1.Text + "\r\t" + lbl_math1.Text + "\r\t" + lbl_total_marks1.Text + "\r\t\n\n";
strForPrint += lbl_marks1.Text + "\r\t\r" + lbl_fa_1_english1.Text + "\r\t\r\t" + lbl_fa_1_evs1.Text + "\r\t\r\t" + lbl_fa_1_hindi1.Text + "\r\t\r\t" + lbl_fa_1_math1.Text + "\r\t\r\t" + lbl_fa_1_total1.Text + "\r\t\r\t\n\n";
strForPrint += lbl_grade1.Text + "\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_fa_1_grade1.Text + "\r\n\n";
strForPrint += lbl_attendance1.Text + "\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_fa_1_attendance1.Text + "\r\n\n\n\n";
strForPrint += lbl_dash_teacher1.Text + "\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_dash_principal1.Text + "\r\n";
strForPrint += lbl_teacher_signature1.Text + "\r\t\r\t\r\t\r\t\r\t\r\t" + lbl_principal_signature1.Text + "\r\n\n\n";
strForPrint += "\r\t\r\t\r\t\r\t" + lbl_grading_norm_index1.Text+ "\r\n\n";
strForPrint += lbl_A_outstainding1.Text + "\r\t" + lbl_B_Excellent1.Text + "\r\t" + lbl_C_very_good1.Text + "\r\n\r\n";
strForPrint += lbl_D_good1.Text + "\r\t\r\t\r\t" + label3.Text + "\r\n\n";
label2.Text = "hello.......";
label2.ForeColor = Color.Green;
Encoding utf16 = Encoding.GetEncoding(1254);
byte[] output = utf16.GetBytes(strForPrint);
FileStream fs = new FileStream(sfd.FileName, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(output, 0, output.Length); //write data into file
bw.Flush();
bw.Close();
fs.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
sfd.Filter = "Word Documents (*.doc)|*.doc";
if (sfd.ShowDialog() == DialogResult.OK)
{
ExportToWord();
}
}
推荐答案
这篇关于从c#windows应用程序导出到带有文本颜色的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!