注册 登录
编程论坛 ASP.NET技术论坛

[求助]两道派凯测试题目

iceqier 发布于 2007-03-27 12:02, 1252 次点击

测试题需求文档
用C#或VB.Net实现


1.对图片文件进行格式转换
对psd, bmp, tif格式的图片进行格式转换,转换为jpg的格式。
并且将原图片的尺寸等比例的转换为原尺寸的60%。

2. 对文本文件进行全文获取
将word、excel、ppt文档的全部文本提取出来,并可将文本存为txt文件。

注:界面由测试者自行设计,无需太复杂,只要能完成上述功能即可。


20 回复
#2
cyyu_ryh2007-03-27 14:02
看起来还有点复杂
顶起
#3
想你的天空2007-03-27 14:13
答案?
#4
BullWolf2007-03-27 14:42

第一题会了。。第二题还要请教高手指点~

#5
iceqier2007-03-27 15:13
4楼的是我班的小干子呀,哈哈,知道你会,猪!!!!第二题还要请高人指点~~~
#6
BullWolf2007-03-27 15:17
5楼的鹌鹑你想死啊。 。当心我揭你老底~
#7
棉花糖ONE2007-03-27 18:27
我晕,别打情骂窍了,会把代码给出来看看
#8
BullWolf2007-03-27 18:35
一下是第一题的答案~我是用winform做的


Stream myStream;
try
{
openFileDialog1.InitialDirectory ="e:\\JPGE";
//定义打开图片的初始路径
this.openFileDialog1.Filter="*.bmp|*.bmp|*.psd|*.psd|*.tif|*.tif";
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialog1.OpenFile())!= null)
{
myStream.Close();
}
System.Drawing.Bitmap bp=new Bitmap(this.openFileDialog1.FileName);
//创建图片对象1
height=bp.PhysicalDimension.Height;
weight=bp.PhysicalDimension.Width;//获取图片的高度和宽度
height=Convert.ToInt32(height*0.6);
weight=Convert.ToInt32(weight*0.6);//将图片的大小缩进60%
count=this.openFileDialog1.FileName.Length;
count=count-3;
str=this.openFileDialog1.FileName.Remove(count,3);//为要转化的图片定义后缀名
Bitmap newbp=new Bitmap(bp,Convert.ToInt32(weight),Convert.ToInt32(height));//创建图片对象2,并定义对象2的大小
newbp.Save(str+"jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
MessageBox.Show("文件转换成功..");
}
else
{
MessageBox.Show("您没有选择文件" );
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
#9
iceqier2007-03-27 20:37
小干子凶什么凶。。。。切。。。有本事把第2道做出来
#10
pacocai2007-03-27 21:30
第二题关于PPT的转换………………不会。
#11
BullWolf2007-03-28 10:03

楼上的。。能把word和excel读出来也行。。。代码展示一下!

#12
skyland842007-03-28 10:43
将word、excel、ppt文档的全部文本提取出来,并可将文本存为txt文件。


这道题目 我曾经考虑过! 其实不难! 好像是调用 这个文档里的 某个函数 就可以提取 他们的文本内容!

#13
bygg2007-03-28 11:12
第二题用StreamWrite 就行了.
#14
BullWolf2007-03-28 15:29
8行的。。。如果可以就简单了,word,excel都是2进制,读出来的都是乱码!!
#15
bygg2007-03-28 15:50
乱码??为什么我的可以??
#16
BullWolf2007-03-28 16:40
那把代码展示一下。。让我学习学习~~!!
#17
bygg2007-03-28 16:45
要是现在有代码,早就发出来了...
#18
BullWolf2007-03-28 16:46
那去写一段嘛。。哈哈~~很快的。。I believe!
#19
iceqier2007-03-28 16:56
你那写啊,别老叫别人写,你不是很有水平的?
#20
BullWolf2007-03-28 17:06

楼上的是谁?

#21
iceqier2007-03-30 18:04
第二题有解了,winfrom做的,答案如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Data.OleDb;
using Office;

namespace Office文件转存
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtbox;
private System.Windows.Forms.Button btnload;
private System.Windows.Forms.Button btnsave;

private OleDbConnection con;
private OleDbDataAdapter dar;
private DataSet ds;

/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtbox = new System.Windows.Forms.TextBox();
this.btnload = new System.Windows.Forms.Button();
this.btnsave = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtbox
//
this.txtbox.Location = new System.Drawing.Point(24, 16);
this.txtbox.Multiline = true;
this.txtbox.Name = "txtbox";
this.txtbox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtbox.Size = new System.Drawing.Size(472, 264);
this.txtbox.TabIndex = 0;
this.txtbox.Text = "";
//
// btnload
//
this.btnload.Location = new System.Drawing.Point(104, 296);
this.btnload.Name = "btnload";
this.btnload.Size = new System.Drawing.Size(96, 23);
this.btnload.TabIndex = 1;
this.btnload.Text = "Load";
this.btnload.Click += new System.EventHandler(this.btnload_Click);
//
// btnsave
//
this.btnsave.Location = new System.Drawing.Point(312, 296);
this.btnsave.Name = "btnsave";
this.btnsave.Size = new System.Drawing.Size(96, 23);
this.btnsave.TabIndex = 2;
this.btnsave.Text = "Save";
this.btnsave.Click += new System.EventHandler(this.btnsave_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(520, 335);
this.Controls.Add(this.btnsave);
this.Controls.Add(this.btnload);
this.Controls.Add(this.txtbox);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Office文件转存工具";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
//读取文档
private void btnload_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Word 文档(*.doc)|*.doc|PowerPoint 演示文稿(*.ppt)|*.ppt|Excel 文件(*.xls)|*.xls";
if(ofd.ShowDialog() == DialogResult.OK)
{
switch(ofd.FileName.Substring(ofd.FileName.LastIndexOf('.'),4))
{
//读取Word文档文本
case ".doc":
txtbox.Text="";
object docname = ofd.FileName;
object readOnly = true;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass wapp = new Word.ApplicationClass();
Word.Document doc = wapp.Documents.Open(ref docname, ref missing,ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing,ref missing);
txtbox.Text = doc.Content.Text;
break;

//读取PowerPoint文档文本
case ".ppt":
txtbox.Text="";
PowerPoint.ApplicationClass pa = new PowerPoint.ApplicationClass();
PowerPoint.Presentation pp = pa.Presentations.Open(ofd.FileName,Office.MsoTriState.msoCTrue,Office.MsoTriState.msoFalse,Office.MsoTriState.msoFalse);
foreach(PowerPoint.Slide slide in pp.Slides)
{
foreach(PowerPoint.Shape shape in slide.Shapes)
{
txtbox.Text = txtbox.Text + shape.TextFrame.TextRange.Text + System.Environment.NewLine;
}
}
break;

//读取Excel文档文本
case ".xls":
txtbox.Text="";
string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ofd.FileName+";Extended Properties='Excel 8.0;HDR=NO;IMEX=1';";
con = new OleDbConnection(str);
con.Open();
string sql = "select * from [sheet1$]";
dar = new OleDbDataAdapter(sql,str);
ds = new DataSet();
dar.Fill(ds);
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
for(int j=0;j<ds.Tables[0].Columns.Count;j++)
{
txtbox.Text += ds.Tables[0].Rows[i][j].ToString()+" ";
}
txtbox.Text += System.Environment.NewLine;
}
break;
}
}
}
catch
{
MessageBox.Show("文件读取错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
if(con != null)
{
ds.Dispose();
dar.Dispose();
con.Dispose();
}
}
}

private void btnsave_Click(object sender, System.EventArgs e)
{
try
{
System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "文本文件(*.txt)|*.txt";
if(sfd.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(sfd.OpenFile());
sw.WriteLine(txtbox.Text);
sw.Close();
MessageBox.Show("文件已保存", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch
{
MessageBox.Show("文件保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
1