Added logic for templates .dot
This commit is contained in:
parent
64f033be20
commit
55e1b7a73d
|
|
@ -7,12 +7,7 @@
|
|||
mc:Ignorable="d"
|
||||
Title="OfficeConverter 1.0" Height="715" Width="1045" Background="#FF1A1A1A">
|
||||
<Grid Background="#FF424242">
|
||||
<Grid.ColumnDefinitions>
|
||||
|
||||
<ColumnDefinition Width="356*"/>
|
||||
<ColumnDefinition Width="689*"/>
|
||||
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid Margin="0,70,0,0" Background="#FF1A1A1A" Grid.ColumnSpan="2">
|
||||
<GroupBox x:Name="grpFolders" Header="grpFolders" Margin="10,10,0,0" RenderTransformOrigin="0.5,0.5" Height="276" VerticalAlignment="Top" HorizontalAlignment="Left" Width="694">
|
||||
<GroupBox.RenderTransform>
|
||||
|
|
@ -34,11 +29,12 @@
|
|||
<Button x:Name="btnDestFolder" Content="btnDest" Margin="545,171,0,0" VerticalAlignment="Top" Click="btnDestFolder_Click"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox x:Name="grpFiles" Header="grpFiles" Margin="709,10,0,0" Height="147" VerticalAlignment="Top" HorizontalAlignment="Left" Width="300">
|
||||
<GroupBox x:Name="grpFiles" Header="grpFiles" Margin="709,10,0,0" Height="182" VerticalAlignment="Top" HorizontalAlignment="Left" Width="300">
|
||||
<Grid>
|
||||
<CheckBox x:Name="chkWord" Content="Word .doc" HorizontalAlignment="Left" Margin="0,10,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="chkExcel" Content="Excel .xls" HorizontalAlignment="Left" Margin="0,45,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="chkPowerpoint" Content="PowerPoint .ppt" HorizontalAlignment="Left" Margin="0,80,0,0" VerticalAlignment="Top"/>
|
||||
<CheckBox x:Name="chkWordTmpl" Content="Wordtemplates .dot" HorizontalAlignment="Left" Margin="0,115,0,0" VerticalAlignment="Top"/>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<GroupBox x:Name="grpSourceFiles" Header="grpSourceFiles" Margin="10,291,0,0" Height="259" VerticalAlignment="Top" HorizontalAlignment="Left" Width="497">
|
||||
|
|
@ -51,13 +47,13 @@
|
|||
<ListBox x:Name="lstDestFiles" ItemsSource="{Binding convertedFiles}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
<Button x:Name="btnConvert" Content="Button" HorizontalAlignment="Left" Margin="835,162,0,0" VerticalAlignment="Top" Width="174" Height="66" Click="btnConvert_Click"/>
|
||||
<Button x:Name="btnConvert" Content="Button" HorizontalAlignment="Left" Margin="10,577,0,0" VerticalAlignment="Top" Width="174" Height="42" Click="btnConvert_Click"/>
|
||||
<Label x:Name="lblState" Content="lblState" HorizontalAlignment="Left" Margin="709,258,0,0" VerticalAlignment="Top" Width="300" Height="28"/>
|
||||
<Button x:Name="btnExport" Content="btnExport" HorizontalAlignment="Left" Height="33" Margin="915,555,0,0" VerticalAlignment="Top" Width="94" Click="btnExport_Click"/>
|
||||
<Button x:Name="btnDelete" Content="btnDelete" HorizontalAlignment="Left" Margin="793,555,0,0" VerticalAlignment="Top" Width="117" Height="33" Click="btnDelete_Click"/>
|
||||
|
||||
</Grid>
|
||||
<Label Content="Office Document Converter" HorizontalAlignment="Left" Margin="10,16,0,0" VerticalAlignment="Top" Width="277" FontSize="20"/>
|
||||
<ComboBox x:Name="cmbLang" HorizontalAlignment="Left" Margin="470,33,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="cmbLang_SelectionChanged" Grid.Column="1"/>
|
||||
<ComboBox x:Name="cmbLang" HorizontalAlignment="Left" Margin="887,33,0,0" VerticalAlignment="Top" Width="120" SelectionChanged="cmbLang_SelectionChanged"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ namespace OfficeConverter
|
|||
bool doWord = false;
|
||||
bool doExcel = false;
|
||||
bool doPPoint = false;
|
||||
bool doWordTmpl = false;
|
||||
string errorFolderEmpty = "";
|
||||
|
||||
public MainWindow()
|
||||
|
|
@ -76,6 +77,7 @@ namespace OfficeConverter
|
|||
doWord = (bool)chkWord.IsChecked;
|
||||
doExcel = (bool)chkExcel.IsChecked;
|
||||
doPPoint = (bool)chkPowerpoint.IsChecked;
|
||||
doWordTmpl = (bool)chkWordTmpl.IsChecked;
|
||||
|
||||
// Check if the background worker is not already running
|
||||
if (!backgroundWorker.IsBusy)
|
||||
|
|
@ -160,6 +162,7 @@ namespace OfficeConverter
|
|||
string[] docFiles = null;
|
||||
string[] xlsFiles = null;
|
||||
string[] pptFiles = null;
|
||||
string[] dotFiles = null;
|
||||
|
||||
if (doWord)
|
||||
{
|
||||
|
|
@ -173,6 +176,10 @@ namespace OfficeConverter
|
|||
{
|
||||
pptFiles = Directory.GetFiles(folderPath, "*.ppt");
|
||||
}
|
||||
if (doWordTmpl)
|
||||
{
|
||||
dotFiles = Directory.GetFiles(folderPath, "*.dot");
|
||||
}
|
||||
|
||||
// Check for null before adding to combinedFiles
|
||||
if (docFiles != null)
|
||||
|
|
@ -187,6 +194,10 @@ namespace OfficeConverter
|
|||
{
|
||||
combinedFiles.AddRange(pptFiles);
|
||||
}
|
||||
if (dotFiles != null)
|
||||
{
|
||||
combinedFiles.AddRange(dotFiles);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Processing files in folder: {folderPath}");
|
||||
|
||||
|
|
@ -284,6 +295,9 @@ namespace OfficeConverter
|
|||
case ".ppt":
|
||||
ConvertPptToPptx(filePath, doSubfolders, doReplace);
|
||||
break;
|
||||
case ".dot":
|
||||
ConvertDocToDotx(filePath, doSubfolders, doReplace);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Handle other file types or show an error message
|
||||
|
|
@ -423,6 +437,45 @@ namespace OfficeConverter
|
|||
KillProcess("WINWORD");
|
||||
}
|
||||
}
|
||||
private void ConvertDocToDotx(string dotFile, bool doSubfolders, bool doReplace)
|
||||
{
|
||||
Word.Application wordApp = new Word.Application();
|
||||
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
|
||||
|
||||
try
|
||||
{
|
||||
Word.Document doc = wordApp.Documents.Open(dotFile);
|
||||
|
||||
string targetFolderPath = "";
|
||||
|
||||
// Use Dispatcher.Invoke to execute code on the UI thread
|
||||
Dispatcher.Invoke(() =>
|
||||
{
|
||||
targetFolderPath = GetTargetFolderPath(doReplace, doSubfolders, dotFile);
|
||||
});
|
||||
|
||||
// Ensure the target folder exists
|
||||
if (!Directory.Exists(targetFolderPath))
|
||||
{
|
||||
Directory.CreateDirectory(targetFolderPath);
|
||||
}
|
||||
|
||||
// Construct the new path for the .dotx file
|
||||
string newDotxPath = Path.Combine(targetFolderPath, Path.ChangeExtension(Path.GetFileName(dotFile), ".dotx"));
|
||||
doc.SaveAs2(newDotxPath, Word.WdSaveFormat.wdFormatXMLTemplate);
|
||||
doc.Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Quit Word and release resources
|
||||
wordApp.Quit();
|
||||
Marshal.ReleaseComObject(wordApp);
|
||||
|
||||
// Ensure Word processes are terminated
|
||||
KillProcess("WINWORD");
|
||||
}
|
||||
}
|
||||
|
||||
private void KillProcess(string processName)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user