다음 C# 코드에서 새 Excel 파일을 만드는 코드가 있습니다. 파일을 저장하려고 할 때 사용자가 저장 위치를 선택하기를 원합니다.Excel 파일 만들기 및 저장
방법 # 1에서 사용자에게 위치를 묻지 않고 SaveCopyAs 통합 문서를 사용하여 파일을 저장할 수 있습니다. 이렇게하면 하나의 파일이 C : \ Temp 디렉토리에 저장됩니다.
방법 2는 파일을 내 Users \ Documents 폴더에 저장 한 다음 사용자에게 위치를 선택하고 두 번째 복사본을 저장하라는 메시지를 표시합니다. 첫 번째 복사본을 Users \ Documents 폴더에 저장하지 않으려면 어떻게합니까? 유 oWB.SaveCopyAs (userselectedlocation)를 호출 할 때
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
Excel.Range oRng;
try
{
//Start Excel and get Application object.
oXL = new Excel.Application();
oXL.Visible = false;
//Get a new workbook.
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
// *****
oSheet.Cells[2, 6] = "Ship To:";
oSheet.get_Range("F2", "F2").Font.Bold = true;
oSheet.Cells[2, 7] = sShipToName;
oSheet.Cells[3, 7] = sAddress;
oSheet.Cells[4, 7] = sCityStateZip;
oSheet.Cells[5, 7] = sContactName;
oSheet.Cells[6, 7] = sContactPhone;
oSheet.Cells[9, 1] = "Shipment No:";
oSheet.get_Range("A9", "A9").Font.Bold = true;
oSheet.Cells[9, 2] = sJobNumber;
oSheet.Cells[9, 6] = "Courier:";
oSheet.get_Range("F9", "F9").Font.Bold = true;
oSheet.Cells[9, 7] = sCarrierName;
oSheet.Cells[11, 1] = "Requested Delivery Date:";
oSheet.get_Range("A11", "A11").Font.Bold = true;
oSheet.Cells[11, 2] = sRequestDeliveryDate;
oSheet.Cells[11, 6] = "Courier Acct No:";
oSheet.get_Range("F11", "F11").Font.Bold = true;
oSheet.Cells[11, 7] = sCarrierAcctNum;
// *****
Method #1
//oWB.SaveCopyAs(@"C:\Temp\" + sJobNumber +".xls");
Method #2
oXL.SaveWorkspace(sJobNumber + ".xls");
}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
}
Kris, http://stackoverflow.com/faq의 FAQ를 읽어보십시오. 태그 작동 방식이 아닙니다. –
이 귀중한 정보에 감사드립니다. – Kris