Good day.
I am newbie in coding and need your help.
I am trying to create an app which will.
- Browse all doc, XLS and ppt files through browse button and will show the file names in TextBox1.
- When I will click Convert Button, it will grab files from TextBox1 and will convert doc to docs, XLS to XLSX and ppt to PPTX.
I am successful till browsing files and showing all files in TextBox1, but unable to get/select files from TextBox1 for conversion.
What am I looking for?
- Get files which are stored in TextBox1 in Convert Button code.
- Convert these files to the relevant new format.
- Show data in loading bar/ Progress Bar so that I can have an idea how long the conversion takes.
What I tried so far from different forums is shared below
using System;
using System.Collections.Generic;
//using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Spire.Doc;
using Spire.Xls;
using Spire.Presentation;
using Microsoft.Office.Interop.Excel;
namespace T_Converter
{
public partial class Form1 : Form
{
private object workbook;
public object ExcelVersion { get; private set; }
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
BTNClear.Enabled = false;
BTNConvert.Enabled = false;
}
private void BTNBrowse_Click(object sender, EventArgs e)
{
var dialog = new OpenFileDialog();
dialog.InitialDirectory = @"\Desktop";
dialog.Title = "Browse old office files";
// dialog.Filter = "Office Files (*.xls)|*.xls";
dialog.DefaultExt = ".xls";
//OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true;
var result = dialog.ShowDialog();
foreach (string file in dialog.FileNames)
{
textBox1.AppendText(Path.GetFileName(file) + Environment.NewLine);
}
BTNConvert.Enabled = true;
BTNClear.Enabled = true;
}
private void BTNClear_Click(object sender, EventArgs e)
{
textBox1.Clear();
BTNClear.Enabled = false;
BTNConvert.Enabled = false;
}
private void BTNClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void BTNConvert_Click(object sender, EventArgs e)
{
}
}
//Create a Workbook instance
namespace ConvertXlsToXlsx
{
class Program
{
static void main(string[] args)
{
//Create a Workbook instance
Excel.Workbook workbook = new Excel.Workbook();
//Load an XLS file
Workbook.LoadFromFile(@"\Desktop\Test.xlsx");
//Convert the file to XLSX format
workbook.SaveToFile(@"C:\Users\Test\Desktop\test.xlsx", ExcelVersion.Version2016);
MessageBox.Show("OK");
}
}
}
}