W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5401

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,858
15년 전 조회 674
15년 전 조회 1,158
15년 전 조회 1,126
15년 전 조회 2,913
15년 전 조회 3,232
15년 전 조회 1,904
15년 전 조회 1,416
15년 전 조회 2,029
15년 전 조회 1,543
15년 전 조회 1,142
15년 전 조회 3,828
15년 전 조회 1,481
15년 전 조회 1,576
15년 전 조회 2,799
15년 전 조회 1,498
15년 전 조회 4,227
15년 전 조회 2,439
15년 전 조회 3,218
15년 전 조회 1,830
15년 전 조회 2,061
15년 전 조회 1,363
15년 전 조회 4,437
15년 전 조회 4,019
15년 전 조회 3,841
15년 전 조회 5,260
15년 전 조회 3,490
15년 전 조회 1,869
15년 전 조회 1,810
15년 전 조회 1,956
15년 전 조회 1,658
15년 전 조회 4,055
15년 전 조회 2,983
15년 전 조회 2,147
16년 전 조회 1,737
16년 전 조회 1,968
16년 전 조회 2,459
16년 전 조회 1,529
16년 전 조회 2,461
16년 전 조회 1,796
16년 전 조회 1,901
16년 전 조회 1,542
16년 전 조회 2,244
16년 전 조회 1,573
16년 전 조회 1,986
16년 전 조회 2,173
16년 전 조회 1,243
16년 전 조회 1,315
16년 전 조회 1,959
16년 전 조회 5,402
16년 전 조회 1,705
16년 전 조회 2,225
16년 전 조회 2,414
16년 전 조회 1,564
16년 전 조회 1,367
16년 전 조회 2,288
16년 전 조회 5,003
16년 전 조회 2,276
16년 전 조회 2,928
16년 전 조회 1,811
16년 전 조회 3,659
16년 전 조회 4,504
16년 전 조회 3,154
16년 전 조회 2,413
16년 전 조회 2,500
16년 전 조회 2,744
16년 전 조회 2,233
16년 전 조회 5,573
16년 전 조회 3,427
16년 전 조회 1,421
16년 전 조회 1,762
16년 전 조회 5,135
16년 전 조회 2,378
16년 전 조회 3,470
16년 전 조회 2,711
16년 전 조회 1,618
16년 전 조회 5,423
16년 전 조회 2,533
16년 전 조회 6,034
16년 전 조회 2,005
16년 전 조회 4,081
16년 전 조회 3,093
16년 전 조회 2,283
16년 전 조회 2,294
16년 전 조회 4,444
16년 전 조회 3,363
16년 전 조회 2,886
16년 전 조회 3,033
16년 전 조회 2,152
16년 전 조회 1,836
16년 전 조회 1,748
16년 전 조회 1,466
16년 전 조회 1,735
16년 전 조회 1,969
16년 전 조회 1,660
16년 전 조회 4,907
16년 전 조회 3,886
16년 전 조회 1,859
16년 전 조회 1,604
16년 전 조회 2,344